• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiling Java with Java

 
cardwell cupp
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there any functions that compile a java source file?
Are there any functions taht can make system calls?
(i.e. c++ has system("command"))
Thanks
Cardwell
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
Yes.
OH! You want specifics.
You would need to compile to a specific platform. Do a google search using +java+compilers and you will find lots.
Actually the JRE uses a JIT compiler (Just in time) which compiles the class files just before using them, so there is really not alot of benefit to a separate compiler. I don't think that there is much performance gained, and it is alot easier to invoke an application using a .bat file instead of an exe. But if you insist.
You can use Runtime.
Try
Runtime.getRuntime().exec("cmd /K del File1.txt");
(the older version of windows use the word "command")
You can also do:
Runtime.getRuntime().exec("cmd /K start run.bat");
and
Runtime.getRuntime().exec(notepad.exe);
 
cardwell cupp
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks tons for you input.
Correct me if I am wrong, the code at the bottom of your reply just runs a batch file (in which I could set up javac Whatever.java) right?
Is it possible to run javac with out a batch file? Is there a function that runs javac on a certain specified file??
(i.e)
public void javac(String fileToBeCompiled)

Thanks for the help!
Cardwell(getting greener all the while)
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that you can just include the parameter with the call to the executable. Course then you need to put it in quotes.
Runtime.getRuntime().exec("javac.exe MyClass.java");
 
cardwell cupp
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks tons!!
Cardwell Cupp(not soo green now!)
 
Helmut Lerch
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Originally posted by cardwell cupp:
public void javac(String fileToBeCompiled)
[/B]

In the JDK 1.1.8 is a class sun.tools.javac.Main for compiling to bytecode. Just call sun.tools.javac.Main.main("fileToBeCompiled.java").
I don't know if there is this class in other JDK's or JRE's
Helmut
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic