好多的打包模式,记录一下 maven+assembly的打包:
项目目录结构:
—-projectName
—–src
—–main
—-bin
—-java
—-profiles
—-resourse
—–test
…….
首先,maven引入assembly插件:
pom.xml
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>src/main/assembly/assembly.xml</descriptor><!--指定插件目录-->
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase><!--绑定到package-->
<goals>
<goal>single</goal><!--只运行一次-->
</goals>
</execution>
</executions>
</plugin>
再定义资源输入目录,加上过滤:
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>${profile.dir}</directory>
<filtering>true</filtering>
<targetPath>${project.build.directory}/conf</targetPath>
</resource>
</resources>
最后加上配置文件的profile:
<properties>
<profiles.dir>src/main/profiles</profiles.dir>
</properties>
<profiles>
<profile>
<id>dev</id>
<activation>
<property>
<name>environment.type</name>
<value>dev</value>
</property>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<profile.dir>${profiles.dir}/dev</profile.dir>
</properties>
<build>
<resources>
<resource>
<directory>${profile.dir}</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</profile>
<profile>
<id>beta</id>
<properties>
<profile.dir>${profiles.dir}/beta</profile.dir>
</properties>
</profile>
<profile>
<id>betaonline</id>
<properties>
<profile.dir>${profiles.dir}/betaonline</profile.dir>
</properties>
</profile>
<profile>
<id>product</id>
<properties>
<profile.dir>${profiles.dir}/product</profile.dir>
</properties>
</profile>
</profiles>
assmbly.xml的配置:
<assembly>
<id>assembly</id>
<formats>
<format>tar.gz</format>
<format>dir</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/conf</directory>
<outputDirectory>conf</outputDirectory>
<fileMode>0644</fileMode><!--0664的权限-->
</fileSet>
<fileSet>
<directory>src/main/bin</directory> <!-- 将src/main/bin目录下的文件打包到根目录(/bin)下. -->
<outputDirectory>/bin</outputDirectory>
<fileMode>0755</fileMode> <!-- 0775的权限 随意权限-->
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
执行maven的 install [package] -p [profile文件的名字] 就可以在打包目录中找到类似的目录接口
projectName
—-bin
—-conf
—-lib
执行过程中可能会存在没有依赖的包,根据提示依赖进来执行就ok了~~~
记录记录
版权声明:本文为zhouren1314原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。