2015-01-20 3 views
9

Mac에서 자동화 테스트를 실행하려고합니다. ,javac : Maven 명령을 실행할 때 Mac에서 1.8이 유효하지 않습니다.

[ERROR] Failure executing javac, but could not parse the error: 
[ERROR] javac: invalid target release: 1.8 
[ERROR] Usage: javac <options> <source files> 
[ERROR] use -help for a list of possible options 
[ERROR] -> [Help 1] 

내가 여기에 검색 :이 오류가 발생했습니다,

Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T18:29:23+01:00) 
Maven home: /usr/local/Cellar/maven/3.2.5/libexec 
Java version: 1.6.0_65, vendor: Apple Inc. 
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home 
Default locale: en_US, platform encoding: MacRoman 
OS name: "mac os x", version: "10.9.5", arch: "x86_64", family: "mac" 

내가 메이븐 명령을 실행하는 경우 :

java version "1.8.0_25" 
Java(TM) SE Runtime Environment (build 1.8.0_25-b17) 
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode) 

와 메이븐 : 나는 JDK 다음과 같이 메이븐 및 자바 설치 허용되는 해결책은 다음과 같습니다.

sudo cp $JAVA_HOME/lib/tools.jar /Library/Java/Extensions/ 

이 명령을 실행했지만 아무 일도 없었습니다! 나는 틀린 것을 모른다.

+0

'which java'와'echo $ JAVA_HOME'의 결과는 무엇입니까? – stevecross

+0

제게있어, Maven 3.2.5에서 3.3.3으로 업그레이드하는 것이 트릭을 만들었습니다. – Benj

답변

22

먼저 파악 : 다음

/usr/libexec/java_home -v 1.8 

을에서 C를 실행하여 JAVA_HOME 환경 변수를 설정 ommand :

export JAVA_HOME=<whatever the output from the previous command was> 

Maven은 최소한 그 터미널 창에서 작동해야합니다.

새 터미널을 열 때마다 이러한 명령을 실행하지 않으려면 프로필에 JAVA_HOME 환경 변수를 설정해야합니다.

+0

감사합니다, 당신은 내 하루를 저장 :) – Ragnarsson

3

아직 작성하지 않았다면 maven-compiler-plugin을 사용하여 Maven에서 사용할 Java 버전을 결정하십시오. (이미에만 <plugin/> 부분을 추가합니다 <build/> 및/또는 <plugins/> 섹션이있는 경우.)

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

: 당신의 pom.xml 파일에 넣고 (당신이 필요로하는 JDK 버전에 <source/><target/> 버전을 변경) 1.8 자바는 명령을 실행하여 설치되어있는

관련 문제