There is no system variable for this. You are going to have to start
from the java.home variable. simply check if there is a bin/javac
under the java.home, if not check if there is a bin/javac under the
directory one level up from the provided directory. If both attempts
fail, then you may have to think of something else. Maybe leave the
option open to run with -Djavac.path=.... on the command line or
configurable in either a properties file or system/user preferences.
And you don't even have to use javac at all. There are ways to call an in-process Java compiler from within a Java class. The API docs will tell you all you need to know.
And you don't even have to use javac at all. There are ways to call an in-process Java compiler from within a Java class. The API docs will tell you all you need to know.
Just a note, you can do this, and many people do, but be aware that
this class is not guaranteed to work the same from version to version,
or even that it will still be there in the next version of java, or even that
it may do something completely other than what it does now in the next
version. Read the sun.* class declaimer in the API docs.
@aniseed, thats originally what I did, but I don't want to rely on that tools package. And with using the other classes as jwenting had stated, there were issues if the computer's system variables weren't set right. Ok, so technically the user should fix those anyway but I'd prefer if that wasn't a direct requirement to make my app work.
I'll just create a preference menu where user's can set the path to their bin directory then use the Process class. Seems to be working fine right now. I'm guessing each OS may use the command line differently? Shouldn't be a problem, I got a mac I can test out a solution on.
Just a note, you can do this, and many people do, but be aware that
this class is not guaranteed to work the same from version to version,
or even that it will still be there in the next version of java, or even that
it may do something completely other than what it does now in the next
version. Read the sun.* class declaimer in the API docs.
And that's why there is java.lang.Compiler for your compilation pleasure.
I've not tried it, but it's there fore JVM creators to implement if they so desire.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.