java.lang.NoClassDefFoundError when running JMS consumer

23,283

-cp option of java command should be placed before the class name:

java -cp .;activemq-all-5.3.2.jar consumer1

Otherwise it's treated as an argument of your main method, not as java's argument. Also note that if you specify classpath with -cp option, you need to include the current directory in order to run .class files from it.

Share:
23,283

Related videos on Youtube

Jeune
Author by

Jeune

I'm an aspiring software architect. I develop in Java and I want to learn Python. Outside coding, I play futbol (soccer) and cook Asian dishes.

Updated on October 16, 2020

Comments

  • Jeune
    Jeune over 3 years

    I am trying to run a class I made however I get this error:

    Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/Destination

    I don't understand why it's not working even when I include the necessary jars in the classpath:

    java consumer1 -cp activemq-all-5.3.2.jar

    • Martijn Verburg
      Martijn Verburg over 13 years
      Is activemq-all-5.3.2.jar in the same directory as consumer1?
    • Martijn Verburg
      Martijn Verburg over 13 years
      Have you checked the activemq-all-5.3.2.jar so make sure it's got that class? (might be a corrupt artifact) you can execute 'jar tvf activemq-all-5.3.2.jar' to see.
    • Jeune
      Jeune over 13 years
      I checked it by expanding the jar in eclipse. It is there.
  • Jeune
    Jeune over 13 years
    I did the -cp option before the class name before. The only difference this time is that I added this ".;" what does that mean? To include in the classpath everything in the current folder? I don't understand why I need to do that when there are no dependencies in the current folder.
  • axtavt
    axtavt over 13 years
    @Jeune: When you run java consumer1, consumer1 is a name of class in the classpath. By default classpath is a current directory, so this command will run consumer1.class from it. When you use -cp option, you override the default classpath, so you need to specify the current folder explicitly in order to run consumer1.class from it.
  • Prinzhorn
    Prinzhorn over 11 years
    NOTE: On Linux you need : as a separator instead of ;. Drove me nuts.