首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java依赖项-运行时插件ClassNotFoundException

Java依赖项-运行时插件ClassNotFoundException
EN

Stack Overflow用户
提问于 2015-08-05 13:59:43
回答 1查看 741关注 0票数 0

我在我的项目中使用TwelveMonkeys库(com.twelvemonkeys.imageio:imageio-tiff:3.1.1)。此外,我正在使用Mavenmaven-依赖-插件一起构建我的项目,并将其配置如下:

代码语言:javascript
复制
<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>

该项目正在正确编译,但它在运行时抱怨ClassNotFoundException: com.twelvemonkeys.io.enc.Decoder。我猜,includeArtifactIds不包括它内指定的库的依赖项(嵌套依赖项)。这就是我如何在我的TwelveMonkeys库中包含pom.xml:

代码语言:javascript
复制
<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>

有人能建议我如何在我最后的FAT JAR文件中包含imageio-tiffimageio-psd所依赖的所有库吗?应该有更好的方法来指定“包含所有依赖项,并有自己的依赖项”。

编辑:

我还使用ProGaurd进行模糊处理,配置如下:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2015-08-05 14:15:22

这是我的pom.xml的一部分,用于构建一个包含所有依赖项的.JAR文件。

代码语言:javascript
复制
<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>

并添加到您的依赖:

代码语言:javascript
复制
<scope>compile</scope>

我通常按以下顺序构建一个罐子:

  • Maven清洁
  • Maven编译
  • Maven软件包

这对我来说包括了所有的库。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31834693

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档