This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

executing dos command in java program

 
C hurst
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
thanks
 
Sean Casey
Ranch Hand
Posts: 625
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ciaran,
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
Posts: 625
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ciara,
I found this article. Take a look at it:
Running external commands in Java applications
 
Blake Minghelli
Ranch Hand
Posts: 331
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done this before:

 
Blake Minghelli
Ranch Hand
Posts: 331
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards,
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic