【maven】-001用maven assembly插件打jar包实现依赖包归档

来源:互联网 发布:ai印花软件 编辑:程序博客网 时间:2024/05/18 02:23

服务化代码层次结构


一、采用mvn生成对应的包
(1) pom.xml类型是war ,使用mvn package 自动将项目依赖的jar包打到web-inf 下的lib文件夹中
(2) pom.xml类型是jar使用 maven的 assembly插件会在${project}/target 文件夹下发现新生成的 {artifactId}-jar-with-dependencies.jar 这个文件

二、如何配置assembly插件
(1)在pom.xml中添加assembly 插件,详见标红部分
<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <parent >
            <artifactId >dubboparent </artifactId >
            <groupId >com.ai </groupId >
            <version >0.0.1-SNAPSHOT </version >
     </parent >
     <modelVersion >4.0.0 </modelVersion >
     <groupId >com.ai </groupId >
     <artifactId >dubboservice </artifactId >
     <version >0.0.1-SNAPSHOT </version >
     <name >dubboservice </name >
     <url >http://maven.apache.org </url >
     <properties >
           <project.build.sourceEncoding >UTF-8 </project.build.sourceEncoding >
     </properties >

     <dependencies >
            <dependency >
                 <groupId >com.ai </groupId >
                 <artifactId >dubbodao </artifactId >
                 <version >0.0.1-SNAPSHOT </version >
            </dependency >
            <dependency >
                 <groupId >org.apache </groupId >
                 <artifactId >zookeeper </artifactId >
                 <version >3.4.5 </version >
            </dependency >
            <dependency >
                 <groupId >org.I0Itec.zkclient </groupId >
                 <artifactId >zkclient </artifactId >
                 <version >0.1 </version >
            </dependency >
     </dependencies >
     <build >
            <plugins >
                 <plugin >
                      <groupId >org.apache.maven.plugins </groupId >
                      <artifactId >maven-compiler-plugin </artifactId >
                      <version >2.3.2 </version >
                      <configuration >
                            <source >1.6 </source >
                            <target >1.6 </target >
                            <encoding >UTF-8 </encoding >
                      </configuration >
                 </plugin >
                 <plugin >
                      <artifactId >maven-assembly-plugin </artifactId >
                      <version >2.2-beta-5 </version >
                      <configuration >
                            <descriptors >
                                 <descriptor >src/main/assembly/src.xml </descriptor >
                            </descriptors >
                      </configuration >
                 </plugin >
            </plugins >
     </build >
</project>
(2)在 main/assembly 下创建 src.xml文件,其中src.xml中的内容
<assembly
     xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
     <id >jar-with-dependencies </id >
     <formats >
            <format >jar </format >
     </formats >
     <includeBaseDirectory >false </includeBaseDirectory >
     <dependencySets >
            <dependencySet >
                 <unpack >false </unpack >
                 <scope >runtime </scope >
            </dependencySet >
     </dependencySets >
     <fileSets >
            <fileSet >
                 <directory >${project.build.outputDirectory} </directory >
            </fileSet >
     </fileSets >
</assembly>
(3)命令行输入mvn assembly:assembly
      会在${project}/target 文件夹下发现新生成的 {artifactId}-jar-with-dependencies.jar 这个文件
    


 (4) 下载对应的依赖包并查看

参考文章: http://blog.csdn.net/e5945/article/details/7777286

0 0