我正在尝试使用maven命令制作一个简单的批处理文件,以执行安装并执行jar主类。
但是编译JAR没有依赖关系,我得到了错误
线程“主”中的异常java.lang.NoClassDefFoundError: akka / actor / ActorSystem
这是我的简单脚本
call mvn clean dependency:copy-dependencies
call mvn package
call cd target
call java -jar distributed-1.0.0.jar
pause
POM.XML
<project 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/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>distributed</groupId>
<artifactId>distributed</artifactId>
<version>1.0.0</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.scala-lang/scala-library -->
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.typesafe.akka/akka-actor -->
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.11</artifactId>
<version>2.5.16</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<outputDirectory>src/main/java/resources/lib
</outputDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source/>
<target/>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.ipca.distributed.Implementations</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
我在这里需要什么?
答案 0 :(得分:0)
我认为创建可运行jar的最简单解决方案是使用Maven Assembly Plugin或Maven Shade Plugin或One Jar Plugin甚至Spring Boot Plugin(如果可行,这并不奇怪) 。您可以找到有关如何使用每个here的更多详细信息。
这些插件确实可以与您拥有的2个组合插件(maven-dependency-plugin和maven-jar-plugin)完全一样。