java.lang.AbstractMethodError 在 Eclipse 中使用 jetty 运行 web 应用程序。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1175282/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:54:49  来源:igfitidea点击:

java.lang.AbstractMethodError running a webapp in Eclipse with jetty.

javaeclipsejetty

提问by stevemac

I am working on a project in eclipse that when I launch using the jetty plugin gives me a

我正在 Eclipse 中开发一个项目,当我使用 jetty 插件启动时,它会给我一个

java.lang.AbstractMethodError: 
au.com.mycopmpany.impl.MyClassDAOImpl.findById(Ljava/lang/Integer;)Ljava/lang/Object;.

This file compiles fine in Eclipse and the code is implementing the method that the error talks about. From my reading this error indicates that "at runtime" the JVM finds a class that doesn't have this method implemented.

这个文件在 Eclipse 中编译得很好,代码正在实现错误所说的方法。从我的阅读来看,这个错误表明 JVM “在运行时”找到了一个没有实现这个方法的类。

But I can assure you that the MyClassDAOImplmost definitely does have the findByIdmethod implemented with the correct signature.

但我可以向您保证,MyClassDAOImpl最肯定的是findById使用正确的签名实现了该方法。

This seems like a bug in the Eclipse compiler; I can fix the issue by running maven packagefrom a command prompt and then running the application within Eclipse works fine.

这似乎是 Eclipse 编译器中的一个错误;我可以通过maven package从命令提示符运行,然后在 Eclipse 中运行应用程序来解决这个问题。

It seems that the Eclipse compiler has some sort of bug in relation to this class. I did read something online about a bug with generics in the Eclipse compiler (which this class does use Generics) but this base class / interface is re-implemented over and over in our code base and it is this class that always has problems.

Eclipse 编译器似乎有一些与此类相关的错误。我确实在网上阅读了一些关于 Eclipse 编译器中泛型错误的内容(这个类确实使用泛型),但是这个基类/接口在我们的代码库中一遍又一遍地重新实现,而这个类总是有问题。

Does anyone know a workaround, or better yet, a fix for this problem?

有谁知道解决方法,或者更好的是,解决此问题的方法?

I can replicate this exception every time, so if an Eclipse compiler developer reads this and this is a known issue, please feel free to contact me for assistance in tracking down the issue.

我每次都可以复制这个异常,所以如果 Eclipse 编译器开发人员阅读了这个并且这是一个已知问题,请随时与我联系以帮助追踪问题。

Update:

更新:

The class with the issue is one of many that implement GenericDAOwhere the Generic interface is defined as:

有问题的类是实现GenericDAOGeneric 接口定义为的众多类之一:

public interface GenericDAO<T, TList> 

The method in question that is failing is:

有问题的方法是:

public T findById(Integer integer) throws APIException;   

回答by duffymo

Try rebuilding your code.

尝试重建您的代码。

I'm guessing that you've got a DAO interface, and the signatures of the interface and the impl differ slightly enough that the compiler doesn't see the interface as fully implemented by the concrete impl class. Maybe Eclipse is out of synch.

我猜你有一个 DAO 接口,接口和 impl 的签名略有不同,编译器没有看到接口完全由具体的 impl 类实现。也许 Eclipse 不同步。

If that doesn't work, see if Eclipse lets you navigate from the interface method to the concrete implementation. If it can't, that's a clue reinforcing what the compiler is telling you.

如果这不起作用,请查看 Eclipse 是否允许您从接口方法导航到具体实现。如果不能,那就是加强编译器告诉您的内容的线索。

Check your CLASSPATH. Maybe the impl that you think is being loaded by the JVM isn't.

检查您的类路径。也许您认为 JVM 正在加载的 impl 不是。

Check the bug list if you think it's a problem with the compiler.

如果您认为这是编译器的问题,请检查错误列表。

If you don't see a bug in list, assume that you're the problem. Lots of people use it; a bug that serious would have been discovered and fixed long ago.

如果您没有在列表中看到错误,请假设您是问题所在。很多人使用它;一个很严重的错误早就被发现并修复了。

Clean out the Jetty deployment - the WAR and all temp files. Rebuild and redeploy. Maybe Jetty is holding onto an older version of the .class file, which would explain why it works on the command line and not when you deploy to the web.

清除 Jetty 部署 - WAR 和所有临时文件。重建和重新部署。也许 Jetty 保留了旧版本的 .class 文件,这可以解释为什么它在命令行上工作,而不是在您部署到网络时。

Assume that you're the problem first, last, and always.

假设您首先、最后和始终是问题所在。

UPDATE: Is there a way to switch the JDK that Eclipse uses? Can you point to a Sun JDK?

更新:有没有办法切换 Eclipse 使用的 JDK?你能指出一个Sun JDK吗?

This is another reason why I detest Eclipse. Your story, if true, would make me even happier to be an IntelliJ user.

这是我讨厌 Eclipse 的另一个原因。如果您的故事属实,我会更高兴成为 IntelliJ 用户。

Question: Are you implementing IBM's generic DAO?

问题:您正在实施IBM 的通用 DAO吗?

回答by rafaeluchoa

Try disabling internal-weaving: (eclipselink.weaving.internal=falsein persistence.xml)

尝试禁用内部编织:(eclipselink.weaving.internal=false在persistence.xml中)

回答by wanglijie

Just clean the project, and then maven build the project. The error disappeared. As a beginner
to eclipse, I think the IDE is like a child, you should have patience to face unstability.

只需清理项目,然后maven构建项目。错误消失了。作为
eclipse的初学者,我认为IDE就像一个孩子,你应该有耐心面对不稳定。

回答by tinyd

I know that you've already said that you can navigate the code and it all checks out OK, but have you tried navigating while debugging? If you break just before findById is invoked and then step in do you arrive into your Impl class? This might give you some hints about possible classpath mixups...

我知道您已经说过您可以导航代码并且一切检查正常,但是您是否尝试在调试时导航?如果您在 findById 被调用之前中断,然后介入,您是否会进入您的 Impl 类?这可能会给你一些关于可能的类路径混淆的提示......

回答by Mark

You say that it runs fine from the command line using the Sun compiler so I assume that both Eclipse and the Sun compiler are outputting their classes into the same directory?

您说它使用 Sun 编译器从命令行运行良好,所以我假设 Eclipse 和 Sun 编译器都将它们的类输出到同一目录中?

I have had similar problems where there seems to be an issue with keeping the class files in sync when using both Eclipse and the Sun compiler. Eclipse uses its own built in compiler instead of the Sun compiler and this will produce different class files for the same code (e.g. the serial version UID's do not match).

我遇到过类似的问题,在使用 Eclipse 和 Sun 编译器时,保持类文件同步似乎存在问题。Eclipse 使用它自己的内置编译器而不是 Sun 编译器,这将为相同的代码生成不同的类文件(例如,串行版本的 UID 不匹配)。

The best solution I have found is to use a seperate bulid folder for Eclipse and the Sun compiler. This way your source if always in sync but the class files cannot conflict with each other.

我发现的最佳解决方案是为 Eclipse 和 Sun 编译器使用单独的 bulid 文件夹。这样你的源如果总是同步但类文件不会相互冲突。

回答by Everyone

Look at your classpath.
It is possible the interface name is duplicated along the classpath in a different package; and that eclipse automagically imported the wrong package.

看看你的类路径。
接口名称可能在不同包中的类路径中重复;并且 eclipse 自动导入了错误的包。

I spent a good deal of time tearing my hair out when it happened /+:

当它发生时,我花了很多时间把头发扯掉/+:

If you already have the solution, could you please post it here too?

如果您已经有了解决方案,能否也将其发布在这里?

回答by Everyone

Is the @Override annotation of any help? You might be able to obtain more information about the problem if you can turn this into a compile-time error.

@Override 注释是否有帮助?如果您可以将其转换为编译时错误,则您可能能够获得有关该问题的更多信息。

Might also be a good idea to fully qualify the relevant class names in the file in question.

完全限定相关文件中的相关类名也可能是一个好主意。