Maven工程打成一个jar包

1:maven-shade-plugin 插件

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <filters>
                <filter>
                  <artifact>*:*</artifact>
                  <excludes>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>META-INF/*.DSA</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                  </excludes>
                </filter>
              </filters>
              <transformers>
                <transformer
                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>META-INF/spring.handlers</resource>
                </transformer>

                <transformer
                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>META-INF/spring.schemas</resource>
                </transformer>

                <transformer
                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>com.test.TestClient</mainClass>
                </transformer>

              </transformers>
            </configuration>
          </execution>
        </executions>
</plugin>

2:maven-assembly-plugin插件

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-dependencies</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/lib</outputDirectory>
              <overWriteReleases>false</overWriteReleases>
              <overWriteSnapshots>false</overWriteSnapshots>
              <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
          </execution>
        </executions>
</plugin>

<plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>

          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass></mainClass>
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
</plugin>

原文地址:https://www.cnblogs.com/xidianzxm/p/8350497.html

时间: 2024-07-30 19:40:14

Maven工程打成一个jar包的相关文章

Maven将代码及依赖打成一个Jar包的方式

Maven可以使用mvn package指令对项目进行打包,如果使用java -jar xxx.jar执行运行jar文件,会出现"no main manifest attribute, in xxx.jar"(没有设置Main-Class).ClassNotFoundException(找不到依赖包)等错误. 要想jar包能直接通过java -jar xxx.jar运行,需要满足: 1.在jar包中的META-INF/MANIFEST.MF中指定Main-Class,这样才能确定程序的

maven工程引用外部jar包

maven工程经常回遇到引用外部jar包,需要先安装在jar包,然后再在工程中pom.xml文件中添加依赖. 示例: 命令行中运行: mvn install:install-file -Dfile=E:\SVN\roadtask\src\main\webapp\WEB-INF\lib\smartupload.jar -DgroupId=org.smartupload -DartifactId=smartupload -Dversion=1.0 -Dpackaging=jar pom.xml中添加

maven 工程下第三方jar 包的引入和打包 war

有时我们需要第三方jar 放在lib 包下 -------位置:/WEB-INF/lib 报编译出错,此时: 然后在打包war 发现问题 pom.xml  中引入 ${basedir}为pom内置的元素 <!--maven 将lib 下包打成war 包--> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</s

Maven工程引入本地jar包

项目中要引入另一个项目的jar包, 不在开源库中. 可以把包复制到本地maven仓库中: 也可以在配置文件中配置路径. 1.在src目录同级创建一个lib文件夹,将jar包拷贝到lib文件夹下 2. 然后在pom.xml中配置包依赖 <dependency> <groupId>com.xxxxxxxl</groupId> <artifactId>xxxxxxxxx</artifactId> <version>0.0.1</ver

maven工程依赖的jar包,在本地仓库有,但是pom.xml文件却报错找不到jar包

问题描述: ? 第一时间查看本地仓库,发现明明有却还报错 ? 解决方案: 查看错误依赖的_remote.repositories文件 ? 正常以来的的_remote.repositories文件 ? 把getui-nexus改成nexus-aliyun. 其中nexus-aliyun是你maven的setting.xml中设置的远程仓库的名字 ? 原文地址:https://www.cnblogs.com/joey-kaka/p/9831101.html

eclipse maven 项目导出为 jar 包

一个 maven 项目有很多依赖,所以最后打出的 jar 一般会很多,且比较大,打成 jar 包的步骤 (注意pom.xml文件中打包类型不能是war包): 1. 把 pom.xml 中依赖的库打成 jar 包:  在工程 pom.xml 所在的目录下,执行命令: mvn dependency:copy-dependencies 所依赖的jar包会导出到目录 target/dependency/中. 2. 把该 maven 项目打成一个 jar 包: 在工程 pom.xml 所在的目录下,执行命

Maven依赖的是本地工程还是仓库jar包?

相信大家都碰见过maven配置的依赖或者是jar包或者是工程,在开发的过程当中,我们当然需要引入的是工程,这样查看maven依赖的文件的时候,就能直接查看到源码. 一.本地工程依赖 举个例子,其架构如下所示(以下均使用eclipse中m2eclipse插件进行演示)-- 此时,这里依赖的"dependency-to-hello"指代的是eclipse工作空间中的工程,这样,我们直接源码依赖的便是工作空间里的源码,这样很方便,也是我们需要的.会注意到,所依赖的"dependen

Maven导出工程依赖的jar包

从Maven仓库中导出jar包:进入工程pom.xml 所在的目录下,输入: mvn dependency:copy-dependencies 会导出到targed/dependency 下面 可以在工程创建lib文件夹,输入以下命令: mvn dependency:copy-dependencies -DoutputDirectory=lib

nexus搭建maven私服及私服jar包上传和下载

nexus搭建maven私服及私服jar包上传和下载 标签: nexus管理maven库snapshot 2017-06-28 13:02 844人阅读 评论(0) 收藏 举报 分类: Maven(1) 版权声明:本文为博主原创文章,未经博主允许不得转载. 一.nexus搭建maven私服及相关介绍 1.下载nexus-2.12.0-01-bundle.zip(版本随意) 2.以管理员身份运行cmd,cd进入解压文件的bin目录,执行nexus.bat install 若未以管理员身份运行则安装