IT박스

Maven이 JDK 1.6을 사용하지만 Java 버전이 1.7 인 이유

itboxs 2020. 6. 6. 09:00
반응형

Maven이 JDK 1.6을 사용하지만 Java 버전이 1.7 인 이유


나는 maven과 MacOS를 처음 사용합니다.

터미널에 maven을 설정했으며 (을 사용하여 mvn -v) 버전 설정을 가져올 때 JDK 1.6을 사용하는 반면 JDK 1.7을 설치 한 것 같습니다. 문제가 있습니까?

내가 입력 한 명령은 다음과 같습니다.

blues:helloworld Ninja$ java -version
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b06)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)`
blues:helloworld Ninja$ mvn -v
Apache Maven 3.1.0 (893ca28a1da9d5f51ac03827af98bb730128f9f2; 2013-06-28 10:15:32+0800)
Maven home: /usr/local/Cellar/maven/3.1.0/libexec
Java version: 1.6.0_51, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: zh_CN, platform encoding: EUC_CN
OS name: "mac os x", version: "10.8.4", arch: "x86_64", family: "mac"

에 다음을 추가하십시오 ~/.mavenrc.

export JAVA_HOME=/Library/Java/JavaVirtualMachines/{jdk-version}/Contents/Home

두 번째 해결책 :

echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile


가입하다

/System/Library/Frameworks/JavaVM.framework/Versions

CurrentJDK심볼릭 링크를 업데이트하여

/Library/Java/JavaVirtualMachines/YOUR_JDK_VERSION/Contents/

예 :

cd /System/Library/Frameworks/JavaVM.framework/Versions
sudo rm CurrentJDK
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/ CurrentJDK

이제 즉시 작동합니다.


당신은 또한 할 수 있습니다

<properties>
      ...  

      <!-- maven-compiler-plugin , aka JAVA Compiler 1.7 -->
      <maven.compiler.target>1.7</maven.compiler.target>
      <maven.compiler.source>1.7</maven.compiler.source>

      ...  
</properties>

어떤 자바 버전을 컴파일할지 maven에게 명시 적으로 알려줄 수도 있습니다. 당신은 maven-compiler-plugin당신의 치어에 추가를 시도 할 수 있습니다 .

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>

maven 프로젝트를 IDE로 가져온 경우 IDE에서 maven 러너가 사용하는 기본 컴파일러에 대한 maven 설정이있을 수 있습니다.


그것은 나를 도왔다. pom.xml에 추가하십시오.

By default maven compiler plugin uses Java 1.5 or 1.6, you have to redefine it in your pom.xml.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

For Eclipse Users. If you have a Run Configuration that does clean package for example.

In the Run Configuration panel there is a JRE tab where you can specify against which runtime it should run. Note that this configuration overrides whatever is in the pom.xml.


I am late to this question, but I think the best way to handle JDK versions on MacOS is by using the script described at: http://www.jayway.com/2014/01/15/how-to-switch-jdk-version-on-mac-os-x-maverick/


Please check the compatibility. I struggled with mvn 3.2.1 and jdk 1.6.0_37 for many hours. All variables were set but was not working. Finally I upgraded jdk to 1.8.0_60 and mvn 3.3.3 and that worked. Environment Variables as following:

JAVA_HOME=C:\ProgramFiles\Java\jdk1.8.0_60 
MVN_HOME=C:\ProgramFiles\apache-maven\apache-maven-3.3.3 
M2=%MVN_HOME%\bin extend system level Path- ;%M2%;%JAVA_HOME%\bin;

@MasterGaurav 's solution is perfectly working,

I normally put the java switch thing into a zsh function:

alias java_ls='/usr/libexec/java_home -V 2>&1 | grep -E "\d.\d.\d[,_]" | cut -d , -f 1 | colrm 1 4 | grep -v Home'

function java_use() {
    export JAVA_HOME=$(/usr/libexec/java_home -v $1)
    echo export "JAVA_HOME=$(/usr/libexec/java_home -v $1)" > ~/.mavenrc
    export PATH=$JAVA_HOME/bin:$PATH
    java -version
}

Then you can run java_ls two get all of the available jvm on your machine, run java_use 1.7 to use the 1.7 version for both java and maven.

참고URL : https://stackoverflow.com/questions/18813828/why-maven-uses-jdk-1-6-but-my-java-version-is-1-7

반응형