• Post Reply Bookmark Topic Watch Topic
  • New Topic

Executing a jar in a Java program  RSS feed

 
laila NiHai
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I just started to learn how to use the ProcessBuilder to invoke another java program (jar). I have added this jar to the "lib" of the calling java program, but when executed I keep getting the error:
Exception in thread "main" java.lang.NoClassDeffoundError:...
Caused by: java.lang.ClassNotFoundException:...


I understand what this error means, but what I don't understand is running the same command directly in the shell works fine, but running it in the java program then i got the mentioned error. Not sure what I did wrong in using the ProcessBuilder (built upon example from the article recommended thisThread

Here is the code:
 
laila NiHai
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone please give me pointers? I've Googled for days...and still haven't found a good example and/or explaination. Any advice would be greatly appreciated!
 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On what line do you get the ClassNotFound?

I also think that ProcessBuilder starts from the working directory where the parent process is executed. If so, then the command line should be "java -jar lib/test.jar" if the test.jar is in the lib-directory.

Edit: Yep, I was right. See http://download.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#directory%28%29 on how to find out the current working directory.
 
laila NiHai
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ove, thank you for your reply....

I get the error at the line:

It looks like the jar file is found and it tries to load the main class... The "test.jar" also has it's own /lib folder... which I tried to also copy it to the main program /lib folder, but still didn't help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!