如何纠正 Java LinkageError 异常?
我正在为WebSphere 6.1 开发一个使用Java servlet 的应用程序。在我的 servlet 中,我定义了 1L 的序列版本 ID。部署并运行我的应用程序后,我收到以下类型的 LinkageError(来自服务器日志):
[5/9/11 15:14:26:868 EDT] 0000001c WebApp
E [Servlet Error]-[ManageRecordsConsumerServlet]: java.lang.Exception:
java.lang.LinkageError: LinkageError while defining class:
<redacted>.docindexupdate.batch.servlet.ManageRecordsConsumerServlet
Could not be defined due to: (<redacted>/docindexupdate/batch/servlet
/ManageRecordsConsumerServlet) class name must be a string at offset=2074
This is often caused by having a class defined at multiple
locations within the classloader hierarchy. Other potential causes
include compiling against an older or newer version of the class
that has an incompatible method signature.
我不确定问题是什么。我之前在定义串行版本 uid 之前就看到过这一点,并认为通过定义它并保持一致,未来对类文件的更新将成功运行。编译或部署到服务器期间没有错误。旧版本的 servlet 是否可能缓存在 WebSphere 实例上的某处(我目前仅部署在我的开发计算机上)?
线路
class name must be a string at offset=2074
也很混乱。
I am developing an application for WebSphere 6.1 which uses a Java servlet. Within my servlet, I have defined a serial vesion ID of 1L. Upon deploying and running my application, I am receiving a LinkageError of the following type (from the server log):
[5/9/11 15:14:26:868 EDT] 0000001c WebApp
E [Servlet Error]-[ManageRecordsConsumerServlet]: java.lang.Exception:
java.lang.LinkageError: LinkageError while defining class:
<redacted>.docindexupdate.batch.servlet.ManageRecordsConsumerServlet
Could not be defined due to: (<redacted>/docindexupdate/batch/servlet
/ManageRecordsConsumerServlet) class name must be a string at offset=2074
This is often caused by having a class defined at multiple
locations within the classloader hierarchy. Other potential causes
include compiling against an older or newer version of the class
that has an incompatible method signature.
I'm not sure what the issue is. I was seeing this previously before defining a serial version uid and figured that by defining that and being consistent, future updates to the class file would run successfully. There are no errors during compilation or deployment to the server. Is it possible that an older version of the servlet is cached somewhere on the WebSphere instance (I am only deploying on my dev machine at the moment)?
The
class name must be a string at offset=2074
line is also confusing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑你有一个 jar 正在两个不同的类加载器中加载。我的意思是,您的 websphere 服务器在启动时会加载该 jar 或具有包含该 jar 的认可目录。您正在部署的 EAR 的库中也有该 jar。两者在运行时可能会发生冲突
我建议找出 ManageRecordsConsumerServlet 属于哪个 jar,然后将其从您的 EAR 库或 Websphere 认可的库中删除(最好是您的 EAR 库)。
I am suspecting you have a jar that is being loaded in two different classloaders. By that I mean, your websphere server on startup loads that jar or has an endorsed directory with that jar. Also your EAR you are deploying has that jar in its lib. The two can conflict at runtime
What I would suggest is to find out which jar ManageRecordsConsumerServlet belongs to and either remove it from your EAR lib or your Websphere endorsed lib (best would be your EAR lib).
这可能是版本控制,但我不这么认为。
当两个类由不同的类加载器加载时,通常会抛出 ClassNotFoundException。
当类通过线路传递/从磁盘缓存加载时,通常会抛出 VersionMismatchException。
当使用具有不同方法签名的类时,会抛出 NoSuchMethodError 或类似错误。
我认为这个案例是一个损坏的类文件。缓存或 JAR 中可能已损坏。
It may be versioning, but I don't thing so.
When two classes loaded by different classloader, a ClassNotFoundException is normally thrown.
When a class is passed over a wire/loaded from disk cache, VersionMismatchException is normally thrown.
When a class with different method signatures is used, NoSuchMethodError or alike is thrown.
I think this case is a corrupted class file. Could be corrupted in cache or in the JAR.