wood burning stoves*
The moose likes Java in General and the fly likes executing dos command in java program 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 "executing dos command in java program" Watch "executing dos command in java program" New topic

executing dos command in java program

C hurst

Joined: Nov 21, 2002
Posts: 4
Hi all,
i am writing a program which asks the user to select a a java file. I would then like to take this file and compile it
File theFile = chooser.getSelectedFile();
How would i compile this file from within my java program

Regards <img src="smile.gif" border="0"> <br />Ciaran
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
I'm trying to do something similar - run a unix command from a java program. From what I understand, you can do this with java.lang.Runtime exec() method. Take a look at it. I'm trying to figure out how to return iformation from that command. I hope that helps.
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
I found this article. Take a look at it:
Running external commands in Java applications
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
I've done this before:

Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
By the way...
If you're using sdk 1.4+ then you can also use the new com.sun.tools.javac.Main class (in tools.jar) to programmatically compile java classes.
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Well, actually the Main Class of tools came out with the 1.2 release.

Dear Licensee,

The Java(TM) 2 Platform, Standard Edition team will be making a change that might impact you.

The change is that the class "sun.tools.javac.Main" (used for compiling java classes) will be removed in J2SE 1.4.
This is not a public API change. If you depend on this class you may be impacted.

If you have questions, please follow-up with your designated Licensee Engineer.

Jill Smith
Java Partner Engineering

You could use the Compile Class of tools. But since neither of these is technically available for the public, and therefore not handled with that consideration in mind, you would be at some risk.

"JavaRanch, where the deer and the Certified play" - David O'Meara
It is sorta covered in the JavaRanch Style Guide.
subject: executing dos command in java program
Similar Threads
Running Programs from JAVA Programs
Javac compiler won't start!! can't compile any code
how to compile a java file from java program
Can't compile file
eclipse ~~compile java file question