Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java code to compile and run another java program

 
Haritha Gorijavolu
Greenhorn
Posts: 21
Debian Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I asked the above question out of curiosity. For example, there is a xxx.java file in some location with it's own main method. What my code is required to do is compile and run xxx.java, given the location of the file. It is possible to do this in java?
 
Nico Van Brandt
Ranch Hand
Posts: 69
IntelliJ IDE Java Mac
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is possible to run dos commands from a java program.

So I assume it's also possible to execute a javac
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use the java.exe that belongs to the JDK you can also use javax.tools.JavaCompiler.
 
Haritha Gorijavolu
Greenhorn
Posts: 21
Debian Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for answering.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic