Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError javax/jms/Message even when specifying classpath

I'm experiencing an error when running certain java code pertaining to JMS. 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
    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:

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:

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:

1) I did also try java -classpath /path/lib/javax.jms.jar:. -jar /path/myjarfile.jar

2) This problem is happening during run-time, not compile-time.

3) So, I have other code that calls the same method in the same jar file that works. There's something not meshing right when calling this code from a particular 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.

like image 682
bdzevel Avatar asked Oct 05 '22 18:10

bdzevel


1 Answers

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.

Can you add a static initializer to JMSManager and JMSProducer to do something like this ?

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.

If not..... well, post what you see :)

like image 66
Nicholas Avatar answered Oct 10 '22 01:10

Nicholas