Kevin K
Kevin K

Reputation: 9584

How does javac locate the Java API classes?

The information on this page provides some good hints and general information, but nothing conclusive.

I know that javac.exe basically just launches 'sun.tools.javac.Main' from 'tools.jar' using Java. I also know that the Java API classes are stored in 'rt.jar' in 'jre/lib' under the JDK. Is this where 'javac.exe' loads the Java API classes from?

I'm wondering about this scenario in particular: suppose I installed jdk1.6.0_17, and later on I installed jdk1.6.0_25. If I run 'javac.exe' from jdk1.6.0_17, will it load the Java API classes from 'rt.jar' in 1.6.0_17 or 1.6.0_25?

The reason I want to know all of this is I'm in a situation where I know the code I'm compiling is going to run on a particular (not most recent) version of Java, and I want to compile using the same exact version of javac and the Java API to ensure compatibility.

Upvotes: 1

Views: 527

Answers (2)

bilash.saha
bilash.saha

Reputation: 7316

By default, classes are compiled against the bootstrap(the runtime classes in rt.jar, internationalization classes in i18n.jar, and others) and extension classes of the platform that javac shipped with.So Yes If You run 'javac.exe' from jdk1.6.0_17, will it load the Java API classes from 'rt.jar' in 1.6.0_17 not from 1.6.0_25.

But javac also supports cross-compiling, where classes are compiled against a bootstrap and extension classes of a different Java platform implementation.

See more at : Cross Compilation if you want to use

Upvotes: 2

DwB
DwB

Reputation: 38320

Set the JAVA_HOME environment variable to the desired JDK. Also change your PATH environment variable to contain the desired JDK bin directory.

Upvotes: 2

Related Questions