NoClassDefFoundError javax/jms/Message even when specifying classpath

47,952

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 :)

Share:
47,952
bdzevel
Author by

bdzevel

Updated on December 10, 2020

Comments

  • bdzevel
    bdzevel over 3 years

    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.

  • bdzevel
    bdzevel about 11 years
    Oh yeah, sorry for the misinformation. I actually did try doing this..... java -classpath /path/lib/javax.jms.jar:. -jar /path/myjarfile.jar
  • bdzevel
    bdzevel about 11 years
    OK I've added the static initializers to the classes in question. I was unable to get any output from JMSManager or JMSProducer, however, the next class up (where these things get called from) is called "JMSService." I added the static initializer to that class and now I get an error as follows: Caused by: java.lang.NoClassDefFoundError: javax/jms/Message at Asci.ActiveBatch.JMSAgent.JMSService.<clinit>(JMSService.jav‌​a:34) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ‌​e Method)
  • Todd Murray
    Todd Murray about 11 years
    You are missing another resource. Decompile Asci.ActiveBatch.JMSAgent.JMSService and look at its dependencies. You will need to find jars for those.
  • bdzevel
    bdzevel about 11 years
    @ToddMurray, I have the source code for that class. The project it's in has a reference to javax.jms.jar, which contains javax.jms.Message ...