Compile and Run Java file using java code

Hi, I wish to write the code for compiling the java file and running the java file.

Say I have a file call myJava.java,
usually using command prompt, what we do is
to compile
"javac myJava.java"
to run
"java myJava myArgs"

But how to achieve this in java code? (notice that I need to input arguments when running java file)
LVL 9
william007Asked:
Who is Participating?
 
objectsCommented:
if u also need to compile programatically see the following:

http://www.javaworld.com/javatips/jw-javatip131.html
0
 
brunoguimaraesCommented:
0
 
objectsCommented:
myJava.main(new String[] { "myArgs" });
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
CEHJCommented:
You don't actually need to create an instance of Main. The compile methods are static
0
 
william007Author Commented:
Really fantastifc, thanks!
0
 
CEHJCommented:
:-)
0
 
CEHJCommented:
If you code is not asynchronous, you'll find it even better to invoke the Eclipse compiler - it's much faster
0
 
william007Author Commented:
Hi, I hav some problem after modifying the solution...
http://www.experts-exchange.com/Programming/Languages/Java/J2SE/Q_22902309.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.