首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Kryo3.0的Maven阴影插件: ClassNotFoundException

使用Kryo3.0的Maven阴影插件: ClassNotFoundException
EN

Stack Overflow用户
提问于 2015-05-01 12:46:04
回答 2查看 544关注 0票数 1

我对Maven相当陌生,我想将一个项目从Kryo2.22更新到3.0.1。在这个项目中,我有以下的依赖项。

代码语言:javascript
运行
复制
<dependency>
    <groupId>com.esotericsoftware.kryo</groupId>
    <artifactId>kryo</artifactId>
    <version>2.22</version>
</dependency>

该项目使用Maven树荫插件创建一个jar文件:

代码语言:javascript
运行
复制
<plugin>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <id>shade-gremlin-groovy</id>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <createDependencyReducedPom>false</createDependencyReducedPom>
                <artifactSet>
                    <includes>
                        <!-- As of Kryo 2.22, this artifact includes both minlog and reflectasm -->
                        <!-- If we upgrade to later a Kryo version, we may have to add includes
                             for minlog and reflectasm (this is true of 2.24.0, not sure about 3) -->
                        <include>com.esotericsoftware.kryo:*</include>
                    </includes>
                </artifactSet>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>reflectasm-1.07-shaded.jar</exclude>
                            <exclude>minlog-1.2.jar</exclude>
                            <exclude>objenesis-1.2.jar</exclude>
                            <exclude>META-INF/MANIFEST.MF</exclude>
                        </excludes>
                    </filter>
                </filters>
                <relocations>
                    <relocation>
                        <pattern>com.esotericsoftware.kryo</pattern>
                        <shadedPattern>com.thinkaurelius.shaded.kryo_2_22</shadedPattern>
                    </relocation>
                    <relocation>
                        <pattern>com.esotericsoftware.minlog</pattern>
                        <shadedPattern>com.thinkaurelius.shaded.minlog_1_2</shadedPattern>
                    </relocation>
                    <relocation>
                        <pattern>com.esotericsoftware.reflectasm</pattern>
                        <shadedPattern>com.thinkaurelius.shaded.reflectasm_1_07</shadedPattern>
                    </relocation>
                    <relocation>
                        <pattern>com.esotericsoftware.shaded.org.objenesis</pattern>
                        <shadedPattern>com.thinkaurelius.shaded.objenesis_1_2</shadedPattern>
                    </relocation>
                </relocations>
                <!-- false below means the shade plugin overwrites the main project artifact (the one with no classifier).
                     false does *not* actually detach the main artifact, despite what the option name suggests. -->
                <shadedArtifactAttached>false</shadedArtifactAttached>
                <minimizeJar>false</minimizeJar>
            </configuration>
        </execution>
    </executions>
</plugin>

但是,除了将版本号更改为3.0.1外,我无法计算应该更改什么( groupId为:<groupId>com.esotericsoftware.kryo</groupId> ),它找不到阴影类(抛出ClassNotfound异常:

代码语言:javascript
运行
复制
java.lang.NoClassDefFoundError: com/thinkaurelius/shaded/kryo_3_0_1/kryo/Serializer
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer.<init>(KryoSerializer.java:71)
at com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer.<init>(StandardSerializer.java:29)
at com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer.<init>(StandardSerializer.java:41)
at com.thinkaurelius.titan.diskstorage.configuration.backend.KCVSConfiguration.<init>(KCVSConfiguration.java:69)
at com.thinkaurelius.titan.diskstorage.configuration.backend.KCVSConfiguration.<init>(KCVSConfiguration.java:57)
at com.thinkaurelius.titan.diskstorage.configuration.KCVSConfigTest.getConfig(KCVSConfigTest.java:31)

我认为问题在于Kryo2.22与Kryo3.0.1有不同的groupId (com.esotericsoftware.kryo),而且Maven无法连接该依赖项。我该怎么解决这个问题?

EN

Stack Overflow用户

回答已采纳

发布于 2015-05-01 13:08:25

在maven阴影插件中,出现了以下一行:

代码语言:javascript
运行
复制
<include>com.esotericsoftware.kryo:*</include>

必须改为:

代码语言:javascript
运行
复制
<include>com.esotericsoftware:*</include>

因为groupId是不同的。所以问题是依赖的错配。

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29987096

复制
相关文章

相似问题

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