ayyoob imani ayyoob imani -4 years ago 63
Java Question

tell maven to use a different version of java from the one that is used to run maven

I'm using maven 3.2.5 to build my project, this version of maven is compatible with java 6.
I want to build a project that enforces using java 5 with maven-enforcer-plugin.

If I set JAVA_HOME to java 5 directory, I can't run maven and if I set JAVA_HOME to java 6 directory, the enforcer plugin complains about java version.

Is there a way to to tell maven to use a different version of java from the one that is used to run maven?

Answer Source

This is situation where you need to use toolchains which can exactly solve the problem. Like running Maven with JDK 7 (for example Maven 3.5.0) but the code needs to be compiled and tested with JDK 6.

See the documentation about toolchains.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download