我使用maven-assembly-plugin创建一个jar-with-dependencies。当我执行.jar文件时,它会抛出
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at com.dg.fs.test.integration.main.FSIntegrationTestMain.<clinit>(FSIntegrationTestMain.java:26)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
这是一个子模块,但我不知道为什么这很重要。
我过去曾使用此插件构建了大量与jar依赖的jar。现在它缺少传递依赖。问题是什么?
感谢。
这是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>
<artifactId>fs-integration-test</artifactId>
<parent>
<groupId>com.dg</groupId>
<artifactId>fs-parent</artifactId>
<version>4.42-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>com.dg</groupId>
<artifactId>fs-jaxb-client</artifactId>
<version>4.55.0.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>com.arcitecta.mf</groupId>
<artifactId>mfclient</artifactId>
<scope>compile</scope>
<!-- <version>4.0.065</version> -->
</dependency>
<dependency>
<groupId>com.digital.globe.dmp</groupId>
<artifactId>mediaflux-utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.dg.fs.test.integration.main.FSIntegrationTestMain</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
答案 0 :(得分:0)
你钉了它,SiKing。在父pom.xml中,它是<scope>provided</scope>
。我在项目pom.xml中将其更改为<scope>compile</scope>
,它运行正常。