[英]Java maven-dependency-plugin ClassNotFoundException at runtime
I am using TwelveMonkeys library ( com.twelvemonkeys.imageio:imageio-tiff:3.1.1
) in my project. 我在我的项目中使用TwelveMonkeys库( com.twelvemonkeys.imageio:imageio-tiff:3.1.1
)。 Also, I am using Maven with maven-dependency-plugin to build my project and I am configuring it like this: 另外,我将Maven与maven-dependency-plugin一起使用来构建我的项目,并按如下方式进行配置:
<plugin>
<!-- Get the dependencies jar files to a common place, for jar signing -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>commons-net,imageio-psd,imageio-tiff</includeArtifactIds>
<!-- <includeGroupIds>com.twelvemonkeys.imageio</includeGroupIds> -->
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
The project is getting compiled properly, but its complaining about ClassNotFoundException: com.twelvemonkeys.io.enc.Decoder
at runtime. 该项目正在正确地进行编译,但是在运行时抱怨ClassNotFoundException: com.twelvemonkeys.io.enc.Decoder
。 I guess, includeArtifactIds
is not including dependencies of the libraries specified inside it (nested dependencies). 我猜想, includeArtifactIds
不包括其中指定的库的依赖关系(嵌套依赖关系)。 This is how I am including TwelveMonkeys libraries in my pom.xml: 这就是我在pom.xml中包含TwelveMonkeys库的方式:
<dependencies>
...
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-psd</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-tiff</artifactId>
<version>3.1.1</version> <!-- Alternatively, build your own version -->
</dependency>
...
</dependencies>
Could anybody please suggest me how can I include all libraries on which imageio-tiff
and imageio-psd
depends in my FINAL FAT JAR file? 有人可以建议我如何在我的FINAL FAT JAR文件中包含imageio-tiff
和imageio-psd
依赖的所有库吗? There just got to be a better way to specify "include all dependencies, with there own dependencies". 只是有一种更好的方法来指定“包括具有自己的依赖关系的所有依赖关系”。
EDIT: 编辑:
I am also using ProGaurd for obfuscation with following config: 我还使用ProGaurd通过以下配置进行混淆:
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.10</version>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>5.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<goals><goal>proguard</goal></goals>
</execution>
</executions>
<configuration>
<proguardVersion>5.2</proguardVersion>
<obfuscate>true</obfuscate>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}.jar</outjar>
<outputDirectory>${project.build.directory}</outputDirectory>
<options>
<option>-allowaccessmodification</option>
...
<option>-keep public class com.twelvemonkeys.** { *; }</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jsse.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
<lib>${java.home}/lib/plugin.jar</lib>
</libs>
</configuration>
</plugin>
This is part of my pom.xml to build an .JAR file with all the dependencies included. 这是我pom.xml的一部分,用于构建包含所有依赖项的.JAR文件。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin
</plugins>
</build>
And add to your dependency: 并添加到您的依赖项:
<scope>compile</scope>
I usually build a jar in the following order: 我通常按以下顺序构建一个jar:
This works for me to include all libraries. 这对我来说包括所有库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.