0

我正在使用与 maven 插件集成的 Eclipse Juno。

我已经在我的系统上安装了 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 运行顺利。

命令行检查: 命令行检查

在我的日食中,我正在构建一个新的 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 clean,它是成功的。但是当我安装 maven 时,它会出现一些 jdk 问题。

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

我在 Eclipse 上的其他 java 程序正在编译和运行良好。除了 Maven 项目。由于上述原因,由于构建失败,因此未生成 war 文件。

如何解决这个问题?

4

2 回答 2

2

您是否在 Eclipse 中运行 Maven 目标?如果是这样,看起来 Eclipse 正在尝试访问 JRE 而不是 JDK:F:\Program Files\Java\jre6\..\lib\tools.jar

尽管JAVA_HOME似乎在 Windows 级别设置正确,但可能是在 Eclipse 中,您正在使用 JRE 而不是 JDK 运行应用程序。在 Eclipse 中,查看已安装的 JRE 列表(Window -> Preferences -> Java -> Installed JREs)。如果您没有 JDK,请在选择 JRE 后单击“编辑”,然后在该对话框中输入 JDK 的位置。

于 2012-12-10T02:28:01.070 回答
1

我假设您正在尝试使用 Eclipse 中的 maven 安装选项。从命令行尝试 mvn install 。如果失败,则问题出在 java 设置(安装、路径、变量)。重新检查您的 java home 是否正确指向 jdk 而不是 jre。还要确保来自 jdk bin 目录的 eclipse javaw.exe。

如果 cmd line install 有效,那么问题在于您的 Maven 项目的 eclipse java 配置。您可以尝试通过以下方式解决它 -

  1. 您应该验证在 eclipse 中设置的项目属性,以确保 java 运行时是正确的。

  2. 您应该在项目方面验证 java 编译设置为 1.6

  3. 您应该在 pom.xml sourcejdk 和 targetjdk 标签中设置 java 编译信息。

于 2012-12-10T02:40:04.450 回答