I am trying to build a Hudson plugin I've modified and it requires jdk1.6. This is fine, but I don't see how I can tell maven where the different jdk is. I've found few mentions on the internet but they don't seem to apply to me. Some suggest adding some config to .m2/settings.xml
but I don't have a settings.xml
. Plus, I don't want to use 1.6 for all maven builds.
One kink is I am using mvn
in cygwin, if that matters at all. It appears I should be able to make the specification in the project pom file, but the existing pom is pretty bare.
So bottom line is, is there a way to specify a jdk for a single invocation of maven?
Maven uses variable $JAVACMD as the final java command, set it to where the java executable is will switch maven to different JDK.
For Java 9 :
As u said "Plus, I don't want to use 1.6 for all maven builds."....So better I will say modify your pom file and specify which jdk version to use.
It will ensure that your particular project uses that version of jdk.
I say you setup JAVA_HOME like Pascal is saying: In cygwin if you use bash as your shell should be "export JAVA_HOME=/cygdrive/c/pathtothejdk" And it never harms to also export the java bin dir to the PATH with "export PATH=${JAVA_HOME}/bin:${PATH}"
and also add maven-enforce-plugin to make sure the right jdk is used. This is a good practice for your pom.
http://maven.apache.org/plugins/maven-enforcer-plugin/usage.html
I had build problem with maven within Eclipse on Windows 7.
Though I observed mvn build was running just fine from command line.
Eclipse was considering as default JVM a JRE installation instead of JDK so it was failing on compilation.
I added to eclipse.ini following line:
Also when starting from eclipse I used in "Goals" section following list:
Compilation error got solved.
Yet another alternative to manage multiple jdk versions is jEnv
After installation, you can simply change java version "locally" i.e. for a specific project directory by:
This will also make mvn use that version locally, when you enable the mvn plugin: