Bitnami Tomcat Stack Maven无法编译

时间:2014-07-13 10:45:14

标签: java maven ubuntu ubuntu-12.04 bitnami

使用Bitnami Tomcat Stack在EC2中创建实例。在几分钟内,一切都很完美。但是在最后阶段部署应用程序maven无法编译源代码。 Eventhoug JAVA_HOME设置完好,无法使用以下错误日志进行编译。

root@ip-172-31-18-89:/mnt/apps/stutzen-backend# echo $JAVA_HOME
/opt/bitnami/java
root@ip-172-31-18-89:/mnt/webapps/stutzen-backend# mvn compile
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building ware27 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ ware27 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 4 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ ware27 ---
[INFO] Compiling 34 source files to /mnt/webapps/stutzen-backend/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] Unable to locate the Javac Compiler in:
  /opt/bitnami/java/../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] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.245s
[INFO] Finished at: Sun Jul 13 10:37:54 UTC 2014
[INFO] Final Memory: 6M/25M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project ware27: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] /opt/bitnami/java/../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

如何处理?

3 个答案:

答案 0 :(得分:1)

问题是默认情况下maven compiler plugin配置为使用Java 1.5编译器(请参阅official documentation中的源和目标选项),而Bitnami Tomcat Stack包含Java 1.7。您需要将项目配置为使用Java 1.7。为此,您可以为maven.compiler.sourcemaven.compiler.target属性定义不同的值,或者定义maven.compiler.compilerVersion,这样也可以。在这两种情况下,您都需要将maven.compiler.fork设置为true。下面的示例显示了如何为每个项目配置:

的pom.xml:

<project>
(...)
  <properties>
    <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
    <maven.compiler.fork>true</maven.compiler.fork>
  </properties>
(...)
</project>

但是,您可能希望为所有项目将这些设置定义为global settings。在这种情况下,您可以编辑($ M2_HOME / conf / settings.xml)中的settings.xml并定义一个始终处于活动状态的配置文件:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" ...>
(...)
  <profiles>
    <profile>
      <id>env-dev</id>
      <properties>
        <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
        <maven.compiler.fork>true</maven.compiler.fork>
      </properties>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>env-dev</activeProfile>
  </activeProfiles>
</settings>

答案 1 :(得分:1)

kaysa的回答是正确的。但是,通过在pom中添加maven-compiler-plugin,可以更轻松地实现解决方案,如下所示:

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

答案 2 :(得分:0)

我不确定这是否对您有所帮助。将配置文件添加到您的pom.xml :)

   <profiles>
        <profile>
            <id>default-tools.jar</id>
            <activation>
                <property>
                    <name>java.vendor</name>
                    <value>Oracle Corporation</value>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>com.sun</groupId>
                    <artifactId>tools</artifactId>
                    <version>1.4.2</version>
                    <scope>system</scope>
                    <systemPath>${java.home}/../lib/tools.jar</systemPath>
                </dependency>
            </dependencies>
        </profile>
    </profiles>

提供您真正的tools.jar地址并使用此个人资料运行maven 如果它没有工作,请忘记并将你的java主页更改为:/opt/bitnami/jdk1.7.0_51/jre :)