使用assembly将maven项目pom.xml中的jar包打包

<span style="font-family: tahoma, arial, sans-serif; background-color: rgb(255, 255, 255);">参考官方网站:</span><a target=_blank href="http://maven.apache.org/plugins/maven-assembly-plugin/usage.html" style="font-family: tahoma, arial, sans-serif; margin: 0px; padding: 0px; color: rgb(68, 68, 68); background-color: rgb(255, 255, 255);">http://maven.apache.org/plugins/maven-assembly-plugin/usage.html</a>

方法一:将pom.xml引入的jar包打到zip文件夹中

  1、pom.xml的配置

<!-- 打包配置 start -->
    <build>
        <plugins>
            <plugin>
                <!-- NOTE: We don't need a groupId specification because the group is
                    org.apache.maven.plugins ...which is assumed by default. -->
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/assembly/src.xml</descriptor>
                    </descriptors>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
                        <phase>package</phase> <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
2、src.xml文件内容
<assembly 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/assembly-1.0.0.xsd">
    <id>package</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>true</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>src/main/bin</directory>
            <outputDirectory>/</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>src/main/config</directory>
            <outputDirectory>config</outputDirectory>
        </fileSet>
    </fileSets>
    <dependencySets>
        <dependencySet>
            <outputDirectory>lib</outputDirectory>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
</assembly>

方法1能把所有引入的包打成jar包,方便自己保存和引入。

  3、最后一步

  cmd进入在项目根目录下,键入“mvn package”,OK完事!

方法二:将pom引入的jar包打进你的项目工程jar包内

  1、pom.xml的配置

<!-- 打包配置 start -->
    <build>
        <!-- <finalName>im-dal-service</finalName>
        <sourceDirectory>src/main/java</sourceDirectory>
        <resources>
            控制资源文件的拷贝
            <resource>
                <directory>src/main/resources</directory>
                <targetPath>${project.build.directory}</targetPath>
            </resource>
        </resources> -->
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/assembly/src.xml</descriptor>
                    </descriptors>
                </configuration>
            </plugin>
        </plugins>
 
    </build>
2、src.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>/lib</directory>
    </fileSet>
  </fileSets>
</assembly>

3、最后一步

  cmd进入在项目根目录下,键入“mvn assembly:assembly”,OK完事!




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值