2012-12-10 82 views
0

我正在使用集成了maven插件的Eclipse Juno。JDK和Maven衝突

我在我的系統上安裝了JDK 1.6。

我的環境變量是

JAVA_HOME - F:\Program Files\Java\jdk1.6.0_37 

MAVEN_HOME - F:\apache-maven-3.0.4 

classpath - ;.;%JAVA_HOME%\lib\tools.jar; 

Path - C:\Program Files\AMD APP\bin\x86;C:\Program Files\Common Files\Microsoft Shared\Windows Live;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Windows Live\Shared;C:\Program Files\QuickTime\QTSystem\;.;%JAVA_HOME%\bin;%MAVEN_HOME%\bin; 

我的JDK和JRE正在順利。

命令行檢查:Command Line Check

在我的日食我建立一個新的Maven web項目應該給我這樣的戰爭文件。

我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.achutha.labs</groupId> 
    <artifactId>01JsfExample</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>war</packaging> 
    <name>01JsfExample</name> 


    <dependencies> 

     <dependency> 
      <groupId>com.sun.faces</groupId> 
      <artifactId>jsf-api</artifactId> 
      <version>2.1.7</version> 
     </dependency> 
     <dependency> 
      <groupId>com.sun.faces</groupId> 
      <artifactId>jsf-impl</artifactId> 
      <version>2.1.7</version> 
     </dependency> 

     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>jstl</artifactId> 
      <version>1.2</version> 
     </dependency> 

     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>servlet-api</artifactId> 
      <version>2.5</version> 
     </dependency> 

     <dependency> 
      <groupId>javax.servlet.jsp</groupId> 
      <artifactId>jsp-api</artifactId> 
      <version>2.1</version> 
     </dependency> 

    </dependencies> 

    <build> 
     <finalName>JavaServerFaces</finalName> 

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

</project> 

如果我Maven的清潔,它是成功的。 但是,當我做maven安裝它給出了一些jdk問題。在Eclipse上

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". 
SLF4J: Defaulting to no-operation (NOP) logger implementation 
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. 
[INFO] Scanning for projects... 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building 01JsfExample 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ 01JsfExample --- 
[debug] execute contextualize 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] Copying 0 resource 
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.1:compile (default-compile) @ 01JsfExample --- 
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! 
[INFO] Compiling 1 source file to F:\Workspace\01JsfExample\target\classes 
[INFO] ------------------------------------------------------------- 
[ERROR] COMPILATION ERROR : 
[INFO] ------------------------------------------------------------- 
[ERROR] Unable to locate the Javac Compiler in: 
    F:\Program Files\Java\jre6\..\lib\tools.jar 
Please ensure you are using JDK 1.4 or above and 
not a JRE (the com.sun.tools.javac.Main class is required). 
In most cases you can change the location of your Java 
installation by setting the JAVA_HOME environment variable. 
[INFO] 1error 
[INFO] ------------------------------------------------------------- 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 0.554s 
[INFO] Finished at: Mon Dec 10 06:54:01 IST 2012 
[INFO] Final Memory: 3M/15M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.1:compile (default-compile) on project 01JsfExample: Compilation failure 
[ERROR] Unable to locate the Javac Compiler in: 
[ERROR] F:\Program Files\Java\jre6\..\lib\tools.jar 
[ERROR] Please ensure you are using JDK 1.4 or above and 
[ERROR] not a JRE (the com.sun.tools.javac.Main class is required). 
[ERROR] In most cases you can change the location of your Java 
[ERROR] installation by setting the JAVA_HOME environment variable. 
[ERROR] -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 

我的其他Java程序進行編譯和運行良好。 不包括maven項目。由於上述原因,構建失敗時不會生成war文件。

如何解決這個問題?

+0

獲取安裝在該系統上的JDK。現在看來你只有JRE。 – Perception

+0

寫入你的控制檯'set JAVA'。這會向您顯示您的JAVA_HOME,看起來像指向JRE而不是JDK – hoaz

回答

2

您是否在Eclipse中運行Maven目標?如果是這樣,它看起來像Eclipse試圖訪問JRE而不是JDK:F:\Program Files\Java\jre6\..\lib\tools.jar

雖然JAVA_HOME似乎在Windows級別正確設置,但它可能是在Eclipse中,您運行的應用程序與一個JRE,不是JDK。在Eclipse中,查看已安裝的JRE列表(窗口 - >首選項 - > Java - >已安裝的JRE)。如果您沒有JDK,請在選擇JRE後單擊'編輯',然後在該對話框中輸入JDK的位置。

+1

我不相信Eclipse會關心JAVA_HOME的價值,因爲您可以設置多個JRE和JDK。 –

+1

你說得對,@tom。我的意思是,儘管JAVA_HOME在Windows級別上可能會很好,但JDK/JRE在Eclipse中是用不同的方式定義的。我可能應該在我的回答中更改這句話 – Juanal

+0

@空白弗洛雷斯... 你的猜測是正確的。 它指向其他JRE,而不是jdk文件夾中的一個。 感謝您的解決方案。 這非常有效。 – bali208

1

我假設你正在嘗試從eclipse使用maven安裝選項。嘗試從命令行安裝mvn。如果這個失敗了,那麼java安裝(安裝,路徑,變量)就是問題。重新檢查你的java家是否正確指向jdk而不是jre。另外從jdk bin目錄確保eclipse javaw.exe。

如果cmd行安裝工作,那麼問題是你的maven項目的eclipse java配置。你可以嘗試解決它 -

  1. 你應該驗證在Eclipse中設置的項目屬性,以確保Java運行時是正確的。

  2. 您應該驗證項目方面的Java編譯設定爲1.6

  3. 您應該設置java編寫信息的pom.xml sourcejdk和targetjdk標籤。

+0

問題出現在eclipse中,它在JDK中採用了錯誤的JRE而不是JRE。 感謝您的回答。 – bali208