maven将项目依赖一起打包
程序员文章站
2022-06-17 14:55:16
...
今天项目打包的时候发现,jar包中只有自己写的主类,没有依赖,于是找了下如何将依赖与主类一起打成一个jar包。
在pom.xml中<build>中添加如下代码:
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scalaVersion>${scala.version}</scalaVersion>
<args>
<arg>-target:jvm-1.8</arg>
</args>
<jvmArgs>
<jvmArg>-Xss4m</jvmArg>
<jvmArg>-Xms512m</jvmArg>
<jvmArg>-Xmx4096m</jvmArg>
</jvmArgs>
</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>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
上一篇: Java之Gradle将所有依赖一起打包
下一篇: 求一个n!中尾数有多少个零
推荐阅读
-
使用electron将vue-cli项目打包成exe的方法
-
将Android封装库通过gradle部署到maven私服并依赖使用
-
visual studio怎么没将项目打包生成dll文件?
-
使用maven-compiler-plugin以及maven-shade-plugin完成maven项目打包
-
Maven项目打包发布时提示test文件的编译错误
-
Maven将依赖包、jar/war包及配置文件输出到指定目录
-
Java微服务项目(maven父子级项目)怎么打包
-
Java全栈程序员之06:IDEA中MAVEN项目依赖及运行
-
解决问题--Maven,IDEA项目External Libraries下只有jdk没有maven依赖
-
Java如何通过Maven管理项目依赖