• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Executing a jar in a Java program

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Let me tell you a story about a man named Jed. He made this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic