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.

Recommended Answers

All 11 Replies

Why would you need that at all?

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.

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.

Member Avatar for iamthwee

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 :sad:

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.

Make a statement with javac!

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.

Thanks for pointing that one out. I haven't tried compiling from
within a program yet, and really don't have a clue as to what project I
would have to be on to make it neccessary, but I may have to take a
look at that and try it out, just for fun.

never needed the functionality either, but it gets asked often enough that I looked into options just for the heck of it.
Guess it was originally intended for IDE makers, and now possibly for appserver builders.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.