• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2040
  • Last Modified:

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)
0
william007
Asked:
william007
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
brunoguimaraesCommented:
0
 
objectsCommented:
myJava.main(new String[] { "myArgs" });
0
 
objectsCommented:
if u also need to compile programatically see the following:

http://www.javaworld.com/javatips/jw-javatip131.html
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now