[英]NoClassDefFoundError javax/jms/Message even when specifying classpath
I'm experiencing an error when running certain java code pertaining to JMS. 我在运行与JMS有关的某些Java代码时遇到错误。 I've been pulling my hair out for 2 days trying to figure this out. 我已经把头发拉了两天试图解决这个问题。
The exception I'm getting is "java.lang.NoClassDefFoundError: javax/jms/Message" 我得到的例外是“java.lang.NoClassDefFoundError:javax / jms / Message”
java.lang.NoClassDefFoundError: javax/jms/Message
at Asci.ActiveBatch.JMSAgent.JMSManager.createMsg(JMSManager.java:195)
at Asci.ActiveBatch.JMSAgent.JMSService.SendMessageHandler(JMSService.java:160)
Without going into TOO much detail, this is referring to this line: 没有详细介绍TOO,这是指这一行:
public static void createMsg(String icf, String url, String cf, String QName, String msgText, String[] props, String user, String pass) throws Exception {
JMSProducer.produceMsg(icf, url, cf, QName, msgText, props, user, pass);
}
(Don't ask why that function is just basically mapping to another one... I didn't originally write this code) (不要问为什么这个函数基本上映射到另一个...我最初没有编写这段代码)
I'm calling this code as 我把这段代码称为
java -jar /path/myjarfile.jar
javax.jms.jar is included in that jar's manifest (and it exists in that location), but just in case I've also tried including a classpath to my lib folder (which contains javax.jms.jar, of course) as follows: javax.jms.jar包含在该jar的清单中(并且它存在于该位置),但以防万一我还尝试将类路径包含到我的lib文件夹(当然包含javax.jms.jar),如下所示:
java -classpath /path/lib:. -jar /path/myjarfile.jar
I've had no luck so far. 到目前为止我没有运气。 I'm not sure what to do or how to debug this problem. 我不知道该怎么做或如何调试这个问题。 Any help would be greatly appreciated. 任何帮助将不胜感激。 Clearly, this code compiles, so these classes must be available (at least) during compile-time. 显然,这段代码会编译,因此这些类必须在编译时(至少)可用。
Thanks. 谢谢。
EDITS: EDITS:
1) I did also try java -classpath /path/lib/javax.jms.jar:. 1)我也尝试了java -classpath /path/lib/javax.jms.jar:。 -jar /path/myjarfile.jar -jar /path/myjarfile.jar
2) This problem is happening during run-time, not compile-time. 2)此问题发生在运行时,而不是编译时。
3) So, I have other code that calls the same method in the same jar file that works. 3)所以,我有其他代码在相同的jar文件中调用相同的方法。 There's something not meshing right when calling this code from a particular jar. 从特定的jar调用此代码时,有些东西没有正确啮合。 I've checked and re-checked my other code to make sure it's identical (which it was/is), so it doesn't seem like a code problem. 我检查并重新检查了我的其他代码,以确保它是相同的(它是/是),所以它似乎不是一个代码问题。 There seems to be some messed up reference or something, somewhere. 在某处似乎有一些混乱的参考或某事。
It is possible that you are having a classloader conflict where one version of javax.jms.Message is loaded in one classloader, and then it is butting heads with a different version loaded from a different classloader. 你可能有一个类加载器冲突,其中一个版本的javax.jms.Message被加载到一个类加载器中,然后它正在使用从不同的类加载器加载的不同版本。
Can you add a static initializer to JMSManager and JMSProducer to do something like this ? 你可以为JMSManager和JMSProducer添加一个静态初始化程序来做这样的事情吗?
static {
System.out.println("MESSAGE CLASSLOADER IN JMSMANAGER:" +
javax.jms.Message.class.getProtectionDomain().getCodeSource().getLocation());
}
If they print out different URLs, it means you have multiple copies of javax/jms/Message.class in the classpath, and your two JMS guys are loading different ones each. 如果他们打印出不同的URL,则意味着你在类路径中有多个javax / jms / Message.class副本,而你的两个JMS人员每个都加载不同的副本。
If not..... well, post what you see :) 如果不是.....好,发布你看到的:)
将.jar
添加到类路径时,需要直接引用jar,而不是它所在的文件夹。
java -classpath /path/lib/JMS.jar:. -jar /path/myjarfile.jar
Create a lib folder inside WEB-INF if it is not there already. 如果WEB-INF中没有lib文件夹,请在其中创建一个lib文件夹。 Put this jar : javax.jms.jar and restart server 把这个jar: javax.jms.jar并重启服务器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.