0

I know there are similar questions posted before and I went through those but still its not working for me.

I am creating a sample JMS test class (chat application) and uses javaee.jar and javax.jms.jar. I can test it through Eclipse IDE and it works fine. But I am trying to run through command prompt so I can run multiple windows.I managed to compile the Chat.java file and it created the Chat.class. But when i try to run it, I get could not find or load main class. These are the commands I used:

From the src/domain folder:

javac -classpath javaee.jar;javax.jms.jar Chat.java---- this created Chat.Class inside domain folder where domain is the package name

The I ran the following command from src folder

java -classpath javaee.jar;javax.jms.jar domain.Chat ---- this gives me the could not find or load main class domain.Chat error message

But when I run without the -classpath parameter(java domain.Chat), it reads the main() and gives me different error since it cant find the jms jar files.

E:\eclipse\Spring\JMSChat\src>java domain.Chat Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/MessageList ener

So basically it finds the Chat.class file when I don't pass in the classpath parameter and it cannot find the class when I use the classpath to add the jars. I tried running it from within domain folder as well as from src folder, but no luck. Any clue what I am doing wrong?

Thanks in advance.

6
  • Have your tried adding . to the classpath ie -classpath .;javaee.jar;javax.jms.jar? Commented Sep 13, 2013 at 21:38
  • @MadProgrammer. Now its picking up the class file but still throws the NoClassdefFoundError:javax/jms/MessageListener Commented Sep 13, 2013 at 21:54
  • Where are the jars located? Try adding the pull path to them in the class path... Commented Sep 13, 2013 at 21:56
  • @MadProgrammer - Ok so now I placed the 2 jar files (javaee.jar and jms.jar) under src folder and its working. Thanks. Commented Sep 13, 2013 at 22:15
  • Not sure that's a good idea, but your at least moving in the right direction... Commented Sep 13, 2013 at 22:17

2 Answers 2

3

Try this

java -classpath javaee.jar;javax.jms.jar;. domain.Chat

By default java uses the current directory in the classpath. When you use the -cp flag, it does not so the path to domain.Chat is not found.

Sign up to request clarification or add additional context in comments.

Comments

0

1) You can run multiple instances of the app from Eclipse, and you can check their outputs by cycling through their allocated consoles by clicking on the arrow next to the console icon

2) try running from your source folder java -classpath .;javaee.jar;javax.jms.jar domain.Chat "." means current dir

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.