| | |
get path to java compiler
![]() |
•
•
Join Date: Mar 2004
Posts: 762
Reputation:
Solved Threads: 38
Title says it all. I've tried getting different system properties with no luck.
Not sure if "java.compiler" is the right one or not, but it always returns null for me. The others I've tried are:
"java.home"
"java.library.path"
"java.class.path"
java.home gives me: c:\java\j2sdk1.4.2_05\jre
But javac is in c:\java\j2sdk1.4.2_05\bin
I don't want to assume that the property always goes to the jre directory with bin just being 1 up from it.
Only other option I've found at this point is to let the user specify where the compiler is.
Not sure if "java.compiler" is the right one or not, but it always returns null for me. The others I've tried are:
"java.home"
"java.library.path"
"java.class.path"
java.home gives me: c:\java\j2sdk1.4.2_05\jre
But javac is in c:\java\j2sdk1.4.2_05\bin
I don't want to assume that the property always goes to the jre directory with bin just being 1 up from it.
Only other option I've found at this point is to let the user specify where the compiler is.
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.
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.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Mmm, I agree with masijade, although this is merely from observation.
Any java ide I have installed, these include netbeans and esclipse, I had to explicitly tell the installer where my jdk was.
I guess a way to automatically do something like that, would be to recursively search through your drives for the offending program (javac).
But that's not purdy, and I assume the file travesing method may slightly differ, depending on which operating system you are using? Yucky
Any java ide I have installed, these include netbeans and esclipse, I had to explicitly tell the installer where my jdk was.
I guess a way to automatically do something like that, would be to recursively search through your drives for the offending program (javac).
But that's not purdy, and I assume the file travesing method may slightly differ, depending on which operating system you are using? Yucky
*Voted best profile in the world*
•
•
•
•
Originally Posted by jwenting
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.
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.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Mar 2004
Posts: 762
Reputation:
Solved Threads: 38
@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.
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.
•
•
•
•
Originally Posted by masijade
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.
I've not tried it, but it's there fore JVM creators to implement if they so desire.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
![]() |
Similar Threads
- Making A Java Compiler... In Java (Java)
- Java Compiler (Java)
- java compiler (Java)
Other Threads in the Java Forum
- Previous Thread: Newbie in java
- Next Thread: problem with SelectionListener
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide image int j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main map method mobile myregfun netbeans nonstatic notdisplaying number online pearl printf problem program project qt researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor






