gpt4 book ai didi

java - Bitnami Tomcat Stack Maven 编译失败

转载 作者:行者123 更新时间:2023-11-30 03:49:50 24 4
gpt4 key购买 nike

使用 Bitnami Tomcat Stack 在 EC2 中创建实例。一切都在几分钟内完美运行。但是在部署应用程序maven的最后阶段无法编译源代码。即使 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

如何处理?

最佳答案

问题是 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 并定义一个始终处于 Activity 状态的配置文件:

<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>

关于java - Bitnami Tomcat Stack Maven 编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24721833/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com