944,058 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 7468
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
May 17th, 2006
0

get path to java compiler

Expand Post »
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.
Similar Threads
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004
May 18th, 2006
0

Re: get path to java compiler

Why would you need that at all?
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
May 18th, 2006
0

Re: get path to java compiler

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.
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004
May 18th, 2006
0

Re: get path to java compiler

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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
May 18th, 2006
0

Re: get path to java compiler

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
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
May 18th, 2006
0

Re: get path to java compiler

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
May 18th, 2006
0

Re: get path to java compiler

Quote 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!
Reputation Points: 48
Solved Threads: 7
Posting Whiz
aniseed is offline Offline
353 posts
since Apr 2006
May 19th, 2006
0

Re: get path to java compiler

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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
May 20th, 2006
0

Re: get path to java compiler

@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.
Reputation Points: 92
Solved Threads: 51
Practically a Posting Shark
Phaelax is offline Offline
856 posts
since Mar 2004
May 21st, 2006
0

Re: get path to java compiler

Quote 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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

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.
Message:
Previous Thread in Java Forum Timeline: Newbie in java
Next Thread in Java Forum Timeline: problem with SelectionListener





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC