File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Runtime.getRuntime to run java

 
cardwell cupp
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the JVM putting the output class file in the classpath?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic