maven 打包
来源:互联网 发布:sql server数据库教程 编辑:程序博客网 时间:2024/06/05 06:40
http://blog.csdn.net/onlyqi/article/details/8194357
要将项目打包,有两种选择:生成一个jar包;或一个包含jar包,配置文件,脚本文件等等的一个zip文件(assembly)。
如果没有在pom中显示的指定,则会使用默认的插件(通过查看effective pom可以看到)并按默认方式打包。
我们常用maven-jar-plugin来生成jar包。如果希望生成assembly,则除了maven-jar-plugin外,再使用插件maven-assembly-plugin来生成zip包。
- <plugin>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.3.1</version>
- <executions>
- <execution>
- <id>default-jar</id>
- <phase>package</phase>
- <goals>
- <goal>jar</goal>
- </goals>
- <configuration>
- <archive>
- <manifest>
- <addClasspath>true</addClasspath>
- <mainClass>com.thomsonreuters.PALFullExtractor.ExtractorMain</mainClass>
- </manifest>
- </archive>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.2</version>
- <executions>
- <execution>
- <id>make-assembly</id>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- <configuration>
- <archive>
- <manifest>
- <mainClass>com.thomsonreuters.PALFullExtractor.ExtractorMain</mainClass>
- </manifest>
- </archive>
- <descriptorRefs>
- <descriptorRef>jar-with-dependencies</descriptorRef>
- </descriptorRefs>
- <descriptors>
- <descriptor>D:\projectname\src\main\assembly/assembly.xml</descriptor>
- </descriptors>
- </configuration>
- </execution>
- </executions>
- </plugin>
注意其中2点:
1,descriptorRef -- jar-with-dependencies 就是将程序依赖的所有第三方类库都打入jar包,这样就不需要在运行时指定class-path了。
2,descriptor -- 指定assembly文件所在的位置。我们还需要创建一个assembly.xml来详细说明package的目录结构和内容。
assembly.xml文件的示例:
- <assembly>
- <id>package</id>
- <formats>
- <format>zip</format>
- </formats>
- <includeBaseDirectory>false</includeBaseDirectory>
- <fileSets>
- <fileSet>
- <directory>src/main/resources/config</directory>
- <outputDirectory>config</outputDirectory>
- <!--将项目中src/main/resources/config下的内容放入packaeg的第一级config目录中-->
- <includes>
- <include>*.xsd</include>
- <include>*.dtd</include>
- <include>*.xml</include>
- <include>*.properties</include>
- <include>*.key</include>
- </includes>
- <lineEnding>lf</lineEnding>
- </fileSet>
- <fileSet>
- <directory>src/main/resources/script</directory>
- <outputDirectory></outputDirectory>
- <!--将项目中src/main/resources/script下的内容放入packaeg中-->
- <includes>
- <include>*.ksh</include>
- <include>*.cmd</include>
- </includes>
- <lineEnding>lf</lineEnding>
- </fileSet>
- </fileSets>
- <dependencySets>
- <dependencySet>
- <outputDirectory>lib</outputDirectory>
- </dependencySet>
- </dependencySets>
- </assembly>
这样打好的package名叫例如:project-1_0.zip中解压后就会得到脚本文件以及另外两个目录config(包含配置文件),和lib目录(包含所有依赖的第三方类库和projectName.jar)
我们还可以在assembly按需要构建更复杂的package结构。
从maven-jar-plugin和maven-assembly-plugin的pom文件可以看到它们都指定了:<phase>package</phase>
这会导致运行mvn package命令时运行这两个插件。
- maven打包
- maven打包
- maven 打包
- maven 打包
- Maven 打包
- Maven 打包
- maven打包
- Maven 打包
- maven打包
- maven 打包
- Maven打包
- maven打包
- maven打包
- maven打包
- maven打包
- maven打包
- maven打包
- Maven打包
- SQLite使用总结3_好多约束Constraints
- vim - 系统剪切板
- JAVA数据库连接池
- SQLite使用总结4_增删改查
- LeetCode - Best Time to Buy and Sell Stock II
- maven 打包
- Remove Norman Security Suite with WindowsUninstaller.Org Removal Tips
- MYSQL中EXPLAIN的说明
- js一些方法的兼容性问题
- poj 2406 poj 1961 个人对吉大KMP模板的理解 KMP 基础题--找周期串
- Python网络页面抓取和页面分析
- 链表面试题
- 黑马程序员-String类的总结和用法
- java遍历Properties文件