maven java项目打包发布插件 maven-assembly-plugin

来源:互联网 发布:淘宝买家虚拟商品骗术 编辑:程序博客网 时间:2024/05/17 07:26

1.插件安装在pom.xml中配置

<plugins>   <plugin>      <artifactId>maven-assembly-plugin</artifactId>      <version>2.4.1</version>      <configuration>        <descriptors> <!--描述文件路径-->                           <descriptor>src/main/assembly/assembly.xml</descriptor>        </descriptors>     </configuration>          <executions>              <execution>                   <id>make-tar-gz</id>                   <!-- 绑定到package生命周期阶段上 -->                   <phase>package</phase>                   <goals>                 <!-- 绑定到package生命周期阶段上 -->                     <goal>single</goal>                   </goals>               </execution>          </executions>      </plugin>  </plugins>

其中中的内容即为assembly.xml文件的路径

2.assembly文件配置

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2                http://maven.apache.org/xsd/assembly-1.1.2.xsd">    <id>distribution</id>    <formats>        <format>tar.gz</format>    </formats>    <includeBaseDirectory>true</includeBaseDirectory>    <fileSets>        <fileSet>            <directory>src/main/resources/${package.environment}</directory>            <outputDirectory>conf</outputDirectory>        </fileSet>        <fileSet>            <directory>src/main/assembly/bin</directory>            <outputDirectory>bin</outputDirectory>        </fileSet>        <fileSet>            <directory>logs</directory>            <outputDirectory>logs</outputDirectory>        </fileSet>        <fileSet>            <directory>dump_files</directory>            <outputDirectory>conf</outputDirectory>        </fileSet>    </fileSets>    <dependencySets>        <dependencySet>            <useProjectArtifact>true</useProjectArtifact>            <outputDirectory>lib</outputDirectory>            <!-- 将scope为runtime的依赖包打包到lib目录下。 -->            <scope>runtime</scope>        </dependencySet>    </dependencySets></assembly>

其中fileSet即为项目目录directory对应最终的输出目录outputDirectory
dependencySet中为运行时依赖包的整理到lib下

3.在配置的时候会遇到一个问题
在pom.xml中配置的指定路径(systemPath)的jar包运行时无法打包到lib下。
解决方案
例如一下systemPath配置

<scope>system</scope>
<systemPath>${project.basedir}/lib/tupuApi_1.1.1.jar</systemPath>

在assembly.xml中配置即可

<fileSet>
<directory>lib</directory>
<outputDirectory>lib</outputDirectory>
</fileSet>

4.线上配置和线下配置区分pom.xml中配置

<profiles>        <profile>            <!-- 本地开发环境 -->            <id>dev</id>            <properties>               <package.environment>dev</package.environment>            </properties>            <!--  <activation>                <activeByDefault>true</activeByDefault>            </activation> -->        </profile>        <profile>            <!-- 测试环境 -->            <id>test</id>            <properties>              <package.environment>test</package.environment>            </properties>        </profile>        <profile>            <!-- 生产环境 -->            <id>product</id>            <properties>      <package.environment>product</package.environment>            </properties>          <activation>                <activeByDefault>true</activeByDefault>            </activation>        </profile>    </profiles>
阅读全文
0 0
原创粉丝点击