2 jdk on the same machine. Set a specific java version to sonarqube-4.5.7

1k Views Asked by At

I have windows 7 OS, java 1.7 and 1.8. Sonar works with 1.8, but I do not want to change my JAVA_HOME environment variable every time I compile the project with sonar. In a wrapper.conf I set wrapper.java.command=C:/Program Files/Java/jdk1.8.0_131/jre/bin/java but it still doesn't work. Also I changed the settings.xml in a .m2 folder putting

 <profiles>
        <profile>
            <id>jdk8</id>
            <properties>
                <JAVA_HOME>C:\Program Files\Java\jdk1.8.0_131</JAVA_HOME>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
......

but without success.

2

There are 2 best solutions below

0
Steffan Petrov On

I couldn't resolve this problem, and for that I've created a .bat file witch executes the commands I need.

echo off
title Ejecuta Sonar

SET PROJECT_HOME=C:\Project\Smarthome

cd %PROJECT_HOME%\xxx\
call mvn clean install

setx -m JAVA_HOME "C:\Program Files\Java\jdk1.8"
setx -m JRE_HOME "C:\Program Files\Java\jre1.8"

cd %PROJECT_HOME%\xxx\
call mvn sonar:sonar

setx -m JAVA_HOME "C:\Program Files\Java\jdk1.7"
setx -m JRE_HOME "C:\Program Files\Java\jre7"

pause
0
cutiko On

My solution is to use sdkman. This allows to install from a variety of Java open-source and to automatize the task. First, install SdkMan so you can configure what you need:

  • You can see the available Java versions with sdk list java
  • You can install as many version as you want with sdk install java VERSION
  • You can set a default for the terminal with sdk default java VERSION
  • And you can change the version with sdk use java VERSION