Animate Dreams Gotta buy them all! (Consumer whore)
Age:36 Gender: Joined: May 01 2004 Posts: 821 Location: Middle Tennessee Offline
|
Posted: Fri Mar 23, 2007 11:48 am Post subject: Calling javac from a Java program |
|
|
|
|
We have a group project in my Java class, and the final product is going to be able to open, display, edit, and save text files. So I thought it would be easy to add a button or a menu option that would make a call to javac with the filename of the file that's opened in the text displayer, but all I found was this: http://www.javaworld.com/javatips/jw-javatip131.html . Which should be exactly what I'm looking for. It discusses a class called com.sun.tools.javac.Main , which has a function compile(), which takes arguments like the command-line javac. But import com.sun.tools.java.Main; doesn't work, because apparently the package doesn't exist. A quick look at the original site, and I see they're discussing JDK 1.2. Now, is there a way to load that package even though it's from an older JDK?
I also tried com.sun.tools.javac.Main.*;, and that didn't work either. I googled the class name, and the closest thing I got to any help is this: http://forum.java.sun.com/thread.jspa?threadID=544470&messageID=2645708 . But, I don't understand that. Mainly, I don't understand this: "put the tools.jar available in jdk\lib directory on the classpath" . I guess that's a suggestion to change the CLASSPATH environment variable(which I currently have set to "."), but I don't understand exactly what to put there. Anyway, if any of you know how to use this class, or know of a better class to use, please tell me. In the mean time, I figure it can't be TOO hard just to call javac in a natural way(I assume Java is capable of running commands, I just don't know how), but at the moment, every site I come to seems intent on teaching me how to call an external program, and a bunch of other stuff all at once, in the same code, and I haven't been able to sort through it yet. :( |
|