java.lang.IncompatibleClassChangeError:实现类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20137309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.IncompatibleClassChangeError: Implementing class
提问by user2793926
Im trying to implement a scheduler to schedule 3 jobs, but on first job implementation only im getting incompatible class change error..
我试图实现一个调度程序来安排 3 个作业,但是在第一个作业实现中,我只收到不兼容的类更改错误..
The error is on line,
错误在线,
JobDetail jobA = JobBuilder.newJob(JobA.class)
.withIdentity(jobKeyA).build();
Any help??
有什么帮助吗??
the complete code is as follow..
完整的代码如下..
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
public class Scheduler1 {
public static void main( String[] args ) throws Exception
{
JobKey jobKeyA = new JobKey("jobA", "group1");
JobDetail jobA = JobBuilder.newJob(JobA.class)
.withIdentity(jobKeyA).build();
JobKey jobKeyB = new JobKey("jobB", "group1");
JobDetail jobB = JobBuilder.newJob(JobB.class)
.withIdentity(jobKeyB).build();
JobKey jobKeyC = new JobKey("jobC", "group1");
JobDetail jobC = JobBuilder.newJob(JobC.class)
.withIdentity(jobKeyC).build();
Trigger trigger1 = TriggerBuilder
.newTrigger()
.withIdentity("dummyTriggerName1", "group1")
.withSchedule(
CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
.build();
Trigger trigger2 = TriggerBuilder
.newTrigger()
.withIdentity("dummyTriggerName2", "group1")
.withSchedule(
CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
.build();
Trigger trigger3 = TriggerBuilder
.newTrigger()
.withIdentity("dummyTriggerName3", "group1")
.withSchedule(
CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
.build();
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.start();
scheduler.scheduleJob(jobA, trigger1);
scheduler.scheduleJob(jobB, trigger2);
scheduler.scheduleJob(jobC, trigger3);
}
}
i have three classes jobA,jobB,jobC but when im adding them to above scheduler im getting error as follows,
我有三个类jobA,jobB,jobC但是当我将它们添加到上面的调度程序时,我得到如下错误,
Exception in thread "main" java.lang.IncompatibleClassChangeError: Implementing class at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:788) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:447) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 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 Scheduler1.main(Scheduler1.java:15)
线程“main”中的异常 java.lang.IncompatibleClassChangeError:在 java.lang.ClassLoader.defineClass(ClassLoader.java:788) 处的 java.lang.ClassLoader.defineClass1(Native Method) 处实现类 java.security.SecureClassLoader.defineClass( SecureClassLoader.java:142) 在 java.net.URLClassLoader.defineClass(URLClassLoader.java:447) 在 java.net.URLClassLoader.access$100(URLClassLoader.java:71) 在 java.net.URLClassLoader$1.run(URLClassLoader.java :361) 在 java.net.URLClassLoader$1.run(URLClassLoader.java:355) 在 java.security.AccessController.doPrivileged(Native Method) 在 java.net.URLClassLoader.findClass(URLClassLoader.java:354) 在 java.lang .ClassLoader.loadClass(ClassLoader.java:424) 在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 在 java.lang.ClassLoader。loadClass(ClassLoader.java:357) 在 Scheduler1.main(Scheduler1.java:15)
采纳答案by Kamlesh Arya
Include the suitable version of cglib in your class path.For eg
在类路径中包含合适版本的 cglib。例如
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
回答by Christian Bongiorno
I had been having this problem as well. After digging through the bowls of the core Java code we discovred that this simple app produced the problem everytime:
我也一直有这个问题。在深入挖掘核心 Java 代码之后,我们发现这个简单的应用程序每次都会产生问题:
public static void main(String[] args) {
System.out.println(AssertionBuilderRegistry.class);
System.out.println(AssertionBuilderRegistryImpl.class);
}
Those classes were determined to be the offenders by putting a Exception breakpoint in the debugger and walking up the call stack until we got some named suspects.
通过在调试器中放置一个异常断点并向上遍历调用堆栈直到我们得到一些命名的嫌疑人,这些类被确定为违规者。
mvn dependency:tree
produces this snippet:
产生这个片段:
\- org.apache.cxf:cxf-bundle-minimal:jar:2.4.10:compile
[INFO] | | +- org.apache.ws.xmlschema:xmlschema-core:jar:2.0.3:compile
[INFO] | | +- org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:jar:1.0.1:compile
[INFO] | | +- org.apache.geronimo.specs:geronimo-annotation_1.0_spec:jar:1.1.1:compile
[INFO] | | +- javax.xml.bind:jaxb-api:jar:2.1:compile
[INFO] | | +- org.apache.neethi:neethi:jar:2.0.4:compile
So, Basically,
所以,基本上,
AssertionBuilderRegistryImpl
must implements/extend
必须实施/扩展
AssertionBuilderRegistry
So, let's go look at CXF version of AssertionBuilderRegistryImpl
那么,我们来看看 CXF 版本的 AssertionBuilderRegistryImpl
public class AssertionBuilderRegistryImpl extends AssertionBuilderFactoryImpl implements
AssertionBuilderRegistry, BusExtension {
and now AssertionBuilderRegistry
现在是 AssertionBuilderRegistry
public interface AssertionBuilderRegistry extends AssertionBuilderFactory { // intellij highlights red here on the extends
So, lets look at AssertionBuilderFactory
所以,让我们看看 AssertionBuilderFactory
public class AssertionBuilderFactory
Well, we have a class implements and interface and that interface extends a class?!
好吧,我们有一个类实现和接口,并且该接口扩展了一个类?!
But wait, this is the correct version pointed out by maven. So, cxf minimal is depending on something it's incompatible with?!
但是等等,这是 maven 指出的正确版本。所以,cxf minimum 取决于它不兼容的东西?!
Let's take a look at the pom for cxf-minimal (snippet):
让我们来看看 cxf-minimal (snippet) 的 pom:
<dependency>
<groupId>org.apache.neethi</groupId>
<artifactId>neethi</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
OK, WTF?! maven dependency says it needs 2.0.4 (which is clearly incompatible) and the pom for this artifact says it needs 3.0.2
好吧,WTF?!maven 依赖说它需要 2.0.4(这显然不兼容)并且这个工件的 pom 说它需要 3.0.2
So, solution:
所以,解决办法:
<dependency>
<groupId>org.apache.neethi</groupId>
<artifactId>neethi</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
explicitly declare the dependency in our main project POM.
在我们的主项目 POM 中明确声明依赖项。
Bug. in Maven. Latest version of maven (3.2.1) does the same.
漏洞。在 Maven。最新版本的 maven (3.2.1) 也是如此。
回答by Hari Nair
I assume that this question is already answered but providing some more details from my own experience.
我假设这个问题已经得到回答,但根据我自己的经验提供更多细节。
I had same java.lang.IncompatibleClassChangeError
in the trace and was thrown when cxf-bundle-2.4.0.jarwas used with neethi-2.x.jar, which was already existing in the class path. As mentioned in Christian Bongiorno's answer, I could find that neethi-3.x.jaris required by cxf-bundle-2.40.jar(I wanted to up vote the answer, but not having enough points to upvote or comment).
我java.lang.IncompatibleClassChangeError
在跟踪中有相同的内容,并且在cxf-bundle-2.4.0.jar与neethi-2.x.jar一起使用时被抛出,它已经存在于类路径中。正如 Christian Bongiorno 的回答中提到的,我发现cxf-bundle-2.40.jar需要neethi -3.x.jar(我想对答案投赞成票,但没有足够的分数来赞成或评论)。
See thislink for more details.
有关更多详细信息,请参阅此链接。
I launched the VM with -verbose
argument mentioned in Brian's answer to thisquestion. This helped to see the class loader logs in catalina.out and could understand that the issue is when org.apache.cxf.ws.policy.PolicyEngine/Impl
classes are loaded, which has dependency to classes from neethi library.
我用-verbose
布赖恩对这个问题的回答中提到的参数启动了虚拟机。这有助于查看 catalina.out 中的类加载器日志,并且可以理解问题是何时org.apache.cxf.ws.policy.PolicyEngine/Impl
加载类,该类依赖于 neethi 库中的类。
In addition to neethi, I have to replace the XmlSchema-1.3.2.jarwith xmlschema-core-2.0.jaras that was also showing conflict. The application is working fine after these changes, however detailed testing is required to confirm. Changes like this are tricky as there can be other run time issues. I wish to rewrite the old code to use latest libraries, but not have time to do so.
除了 neethi,我必须用xmlschema-core-2.0.jar替换XmlSchema-1.3.2.jar,因为这也显示出冲突。应用程序在这些更改后工作正常,但需要进行详细的测试来确认。像这样的更改很棘手,因为可能存在其他运行时问题。我希望重写旧代码以使用最新的库,但没有时间这样做。