get path to java compiler

Reply

Join Date: Mar 2004
Posts: 762
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

get path to java compiler

 
0
  #1
May 17th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: get path to java compiler

 
0
  #2
May 18th, 2006
Why would you need that at all?
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 762
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: get path to java compiler

 
0
  #3
May 18th, 2006
What difference does it make?

I've made an IDE for java and would prefer to have the path auto-config to whatever system im on, ie not a hard-coded pathname like I have now.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,281
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 243
masijade's Avatar
masijade masijade is online now Online
Nearly a Posting Maven

Re: get path to java compiler

 
0
  #4
May 18th, 2006
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.
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 376
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: get path to java compiler

 
0
  #5
May 18th, 2006
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
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: get path to java compiler

 
0
  #6
May 18th, 2006
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 353
Reputation: aniseed is an unknown quantity at this point 
Solved Threads: 6
aniseed's Avatar
aniseed aniseed is offline Offline
Posting Whiz

Re: get path to java compiler

 
0
  #7
May 18th, 2006
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.
Make a statement with javac!
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,281
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 243
masijade's Avatar
masijade masijade is online now Online
Nearly a Posting Maven

Re: get path to java compiler

 
0
  #8
May 19th, 2006
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.
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 762
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: get path to java compiler

 
0
  #9
May 20th, 2006
@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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: get path to java compiler

 
0
  #10
May 21st, 2006
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.
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC