maven自定义打包备忘
2014-07-28 15:40
211 查看
之前一直是用ant进行打包,使用过的人都知道,其灵活性是不用置疑的。
现在公司新建的工程序都采用一maven来打包了,以于java或web工程来说,用maven打包也是很方便的,特别是其对jar包依赖的管理。但我现在的需求是打一个特殊的包,非java也非web工程序。
需求是这样的:对tomcat过行打包,并且附带一安装脚本,目录结构如下
其中pom.xml和tar.xml是打包时maven要使用的文件,主要是想将目录apache-tomcat-6.0.41和install.sh文件打包到一下后辍名为.tar.gz的压缩包中。
最开始无从下手,后来在网上搜了一把,发现有个叫maven-assembly-plugin的插件可以实现自定义打包,其pom.xml文件配置如下:
其中maven-svn-revision-number-plugin主要是用于从svn中获取工程的svn版本号,可以去掉,只是打包的文件名中没有svn版本号而也。
tar.xml是maven-assembly-plugin插件执行时要用到的配置文件,具体如下:
现在公司新建的工程序都采用一maven来打包了,以于java或web工程来说,用maven打包也是很方便的,特别是其对jar包依赖的管理。但我现在的需求是打一个特殊的包,非java也非web工程序。
需求是这样的:对tomcat过行打包,并且附带一安装脚本,目录结构如下
其中pom.xml和tar.xml是打包时maven要使用的文件,主要是想将目录apache-tomcat-6.0.41和install.sh文件打包到一下后辍名为.tar.gz的压缩包中。
最开始无从下手,后来在网上搜了一把,发现有个叫maven-assembly-plugin的插件可以实现自定义打包,其pom.xml文件配置如下:
<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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>server</groupId> <artifactId>tomcat</artifactId> <version>6</version> <!-- <packaging>jar</packaging> --> <name>tomcat</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format> <buildTime>${maven.build.timestamp}</buildTime> <version>6</version> <createTime>${buildNumber}</createTime> </properties> <build> <plugins> <plugin> <groupId>com.google.code.maven-svn-revision-number-plugin</groupId> <artifactId>maven-svn-revision-number-plugin</artifactId> <version>1.7</version> <executions> <execution> <!-- 这个阶段应该写maven打包之前的生命周期,否则打包时候获取不到版本号 --> <phase>validate</phase> <goals> <goal>revision</goal> </goals> </execution> </executions> <configuration> <entries> <entry> <prefix>SVN</prefix> </entry> </entries> </configuration> <!-- svn版本1.7以上才需要配这个依赖,1.6及以下使用默认即可 --> <dependencies> <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId> <version>1.8.2</version> </dependency> </dependencies> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.2-beta-5</version> <executions> <!--执行器 mvn assembly:assembly --> <execution> <id>tar-tomcat</id><!--名字任意 --> <phase>package</phase><!-- 绑定到package生命周期阶段上 --> <goals> <goal>single</goal><!-- 只运行一次 --> </goals> <configuration> <finalName>Tomcat_${version}_${SVN.revision}_${buildTime}</finalName> <appendAssemblyId>false</appendAssemblyId> <descriptors> <!--描述文件路径 --> <descriptor>tar.xml</descriptor> </descriptors> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
其中maven-svn-revision-number-plugin主要是用于从svn中获取工程的svn版本号,可以去掉,只是打包的文件名中没有svn版本号而也。
tar.xml是maven-assembly-plugin插件执行时要用到的配置文件,具体如下:
<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>release</id> <formats> <format>tar.gz</format> </formats> <fileSets> <fileSet> <directory>${project.basedir}/apache-tomcat-6.0.41</directory> <outputDirectory>/apache-tomcat-6.0.41</outputDirectory> </fileSet> <fileSet> <directory>${project.basedir}/</directory> <lineEnding>unix</lineEnding> <fileMode>777</fileMode> <includes> <include>install.sh</include> </includes> <outputDirectory>\</outputDirectory> </fileSet> </fileSets> <dependencySets> <dependencySet> <useProjectArtifact>false</useProjectArtifact> <!-- 将scope为runtime的依赖包打包到lib目录下。 --> <!-- <outputDirectory>lib</outputDirectory> --> <scope>runtime</scope> </dependencySet> </dependencySets> </assembly>
相关文章推荐
- 初学maven(5)-使用assembly plugin实现自定义打包
- maven打包自定义包名
- 利用Maven 自定义打包
- maven 自定义打包插件maven-assembly-plugin不完全记录
- maven多环境配置打包(自定义properties)
- Maven学习总结(27)——Maven自定义打包插件maven-assembly-plugin详解
- Maven学习总结(27)——Maven自定义打包插件maven-assembly-plugin详解
- maven自定义插件 jenkis打包 jar包版本校验dependency-check-plugin:check
- maven-使用assembly自定义打包
- 利用Maven 自定义打包
- maven打包web项目时同时打包为war和jar文件(备忘用)
- Maven打包自定义时间戳格式
- 初学maven(5)-使用assembly plugin实现自定义打包
- maven:用appassembler-maven-plugin打包含有自定义目录的JAVA程序
- maven 自定义打包
- 利用maven-assembly-plugin进行自定义格式打包
- [解决]maven打包如何指定自定义外部包的问题
- Maven build插件之Maven-assembly-plugin自定义打包
- 初学maven(5)-使用assembly plugin实现自定义打包
- maven打包根据指定参数,自定义war包名称