On my machine I have two java versions installed: (1.6 and 1.7 installed manually by me). I need both of them for different projects. But for Maven I need 1.7, now my Maven uses 1,6 java version, how can I set Maven to use 1.7?
相关问题
- Include pom.xml in Jar with gradle
- What order does maven find its dependencies?
- proguard causing EnumMap NPE on dynamically declar
- Java 7 G1GC strange behaviour
- Maven: How to read the Parent POM version
相关文章
- IDEA2020 安装maven 插件后,springboot程序 SpringBootApplic
- pom文件中的插件定义
- pom.xml中的project为何报红
- Hibernate Tutorial - Where to put Mapping File?
- Cannot use org.jvnet.jax-ws-commons.jaxws-maven-pl
- New Maven install: mvn -version java.lang.ClassNot
- What's the difference between archetype.xml an
- NoNodeAvailableException[None of the configured no
Maven uses the
JAVA_HOME
parameter to find which Java version it is supposed to run. I see from your comment that you can't change that in the configuration.JAVA_HOME
parameter just before you start maven (and change it back afterwards if need be).mvn
(non-windows)/mvn.bat
/mvn.cmd
(windows) and set your java version explicitly there.To avoid any impact to your project and to your Environment Variables, you can configure the Maven Compiler Plugin just to the project's POM, specifying the Source and Target java version
One simple solution to the problem -
On Mac, it would look something like -
PS: One special case that i found is the above given command does not work on 'fish' shell. I also had bash shell available and it worked fine there. just use command 'bash' to switch to bash shell.
On windows
If you do not want to change your
JAVA_HOME
variable inside the system variables.Edit your
mvn.bat
file and add a line like thisThis can be done after
@REM ==== START VALIDATION ====
like mentionned by @JonathanOn Mac (& Linux ?)
If you do not want to change your
JAVA_HOME
variable inside your~/.bashrc
or~/.bash_profile
you can create a
~/.mavenrc
file and redefine yourJAVA_HOME
using the java_home toolSanity Check
You can verify that everything is working fine by executing the following commands. The jdk version should be different.
mvn -version
then
java -version
Also you can have two versions of maven installed, and edit one of them, editing here:
replacing your %java_home% appearances to your java desired path. Then just execute maven from that modified path
Without changing Environment Variables, You can manage java version based on the project level by using Maven Compiler Plugin.
Method 1
Method 2