Using libraries from one JDK and running with another JDK?

Does anyone know if it's possible to have a project use the
libraries from one JDK, say 1.3.1, while using another JDK,
say 5.0, for running/debugging?

I want to make sure that I don't use any library methods that
are not available in 1.3. At the same time, I want to take
advantage of the improvements (faster, shared class data, etc)
available in 5.0.

Has anyone tried this (and succeeded)?

(I do realize that I need to run test with 1.3 as well, but
that can be done offline.)

Thanks,

/Mikael

4 comments
Comment actions Permalink

At the bottom of the page where you specify your JDK is a language level
for project setting. It actually defaults to 1.3 (instead of the same
version as your JDK).

I currently compile and run against JDK5, but cannot use any of the
features. Stupid politics.

Norris Shelton
Sun Certified Java Programmer




Mikael Karlsson wrote:

>Does anyone know if it's possible to have a project use the
>libraries from one JDK, say 1.3.1, while using another JDK,
>say 5.0, for running/debugging?
>
>I want to make sure that I don't use any library methods that
>are not available in 1.3. At the same time, I want to take
>advantage of the improvements (faster, shared class data, etc)
>available in 5.0.
>
>Has anyone tried this (and succeeded)?
>
>(I do realize that I need to run test with 1.3 as well, but
>that can be done offline.)
>
>Thanks,
>
>/Mikael
>

>

0
Comment actions Permalink

NS> At the bottom of the page where you specify your JDK is a language
NS> level for project setting. It actually defaults to 1.3 (instead of
NS> the same version as your JDK).

This is mostly syntax only limitation:

1.5 - can use enumsautoboxing

1.4 - can use assert

1.3 - can use none of the above.


I've already seen a case where compiling against 1.5 makes the code not run
against earlier vm's:

new BigDecimal(0)

compiled in 1.5 with 1.4 only features. Runs ok under 1.5, fails under 1.4
with no such method assertion.

-> 1.5 introduced a new constructor new BigDecimal(int) that doesn't exist
in 1.4



MK> Does anyone know if it's possible to have a project use the
MK> libraries from one JDK, say 1.3.1, while using another JDK, say 5.0,
MK> for running/debugging?

IIRC, I've seen references to adding the rt.jar of an earlier vm to the bootclasspath
(or some variable like this) of the compiler/runner for just this purpose.



0
Comment actions Permalink

Setting the language level doesn't prevent me from using
classes that are only available in later JDK versions.

0
Comment actions Permalink

Can't you just use modules? You might need an extra dummy one, but the one for which you want to constrain the classes, set its jdk to 1.3. Create another module that uses jdk1.5 and have it depend on the module that uses jdk 1.3. Then in your Run configurations, make sure it's using the 1.5 module. Now you should get the behavior of compiling with jdk1.3 but running with jdk1.5.

0

Please sign in to leave a comment.