tags:

views:

34

answers:

2

Hi All,

I need two versions of Java ie. Java5 and Java6 on the same machine, as some of my projects support Java6 and some supports Java5. So I made it by putting the path of Java6 in JAVA_HOME and Java5 in JAVA5_HOME. I added both the JAVA_HOMEs in the PATH variable.

But when I do java -version, then by default I am getting the following result

java version "1.6.0" Java(TM) SE Runtime Environment (build 1.6.0-b105) Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

Is it possible to get Java5 also along with Java6??

Also I would like to know that, is it possible to configure maven2 with two versions of Java (Java1.6 & Java1.5) and use the required version for building the project in the run time?

A: 

So I made it by putting the path of Java6 in JAVA_HOME and Java5 in JAVA5_HOME. I added both the JAVA_HOMEs in the PATH variable.

Not really a good idea (and one of them will be first on the path anyway). You should add JAVA_HOME only and make it point to the JDK you want to use (and switch on demand).

Also I would like to know that, is it possible to configure maven2 with two versions of Java (Java1.6 & Java1.5) and use the required version for building the project in the run time?

No. Maven uses JAVA_HOME, you can only use one JDK at a time.

If you want to build the same project with 2 different JDKs, your best option would be to use a CI engine like Hudson and to setup a build matrix.

Pascal Thivent
I changed JAVA_HOME to JAVA5_HOME in mvn.bat, and it built the project with Java5.I was wondering if there is any setting where we can provide both JAVA_HOME and JAVA5_HOME and chose the compiler in the run time or by any other way?
deejay
@deejay08: As I wrote, no. And I don't see the point of modifying `mvn.bat`. Change the `JAVA_HOME` environment variable instead of modifying all scripts depending on `JAVA_HOME`.
Pascal Thivent
thanks..........
deejay
+1  A: 

One way to achieve this is documented at the maven-compiler-plugin site.

Personally I would first try to use the source and target parameters of the compile mojo (documented here), as that would allow you to target both 1.5 and 1.6 without switching to another Java compiler.

andri
Changing the compiler level != using another JDK (and doesn't prevent you from using classes that don't exist in previous versions).
Pascal Thivent