This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Using Runtime.getRuntime to run java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Using Runtime.getRuntime to run java" Watch "Using Runtime.getRuntime to run java" New topic
Author

Using Runtime.getRuntime to run java

cardwell cupp
Ranch Hand

Joined: Aug 16, 2001
Posts: 66
I am using
Runtime.getRuntime.exec("javac " + path + file)
to compile a java file...it works just fine.
Then when I use the same code to run it,
Runtime.getRuntime.exec("java " + path + class)
it comes back with a NoClassDeff error. Doesn't that usually mean that the classpath is not set correctly? But if I can do it with javac then why not java?
Thanks
Cardwell
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Is the JVM putting the output class file in the classpath?


"JavaRanch, where the deer and the Certified play" - David O'Meara
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
My guess: use the -d option of javac to make javac create the class files in appropriate directories for their packages. E.g. if Test.java has a class Test in package mypkg, then
<pre>javac -d classdir Test.java</pre>
will create the file in classdir/mypkg/Test.class. I've never figured out why this isn't automatic, but you need to specify the option.


"I'm not back." - Bill Harding, Twister
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Using Runtime.getRuntime to run java
 
Similar Threads
Print simple jpeg image using java
How to print barcode labels using barcode4j?
How to compile only specific .java files, not the whole src
how to finish the process forcibly?
problem with waiting for a process