[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project my-app: Compilation failure: Unable to locate the Javac Compiler in:
...\jre\lib\tools.jar
Please ensure you are using JDK, not JRE.
复制代码
解决方案:
1. 确保使用JDK而不是JRE编译项目。
2. 在POM文件中明确指定Java编译器版本:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerVersion>1.8</compilerVersion>
<fork>true</fork>
<executable>${JAVA_HOME}/bin/javac</executable>
</configuration>
</plugin>
</plugins>
</build>
复制代码
1. 设置环境变量JAVA_HOME指向JDK安装目录。
6.2 依赖下载失败
问题描述:
[ERROR] Failed to execute goal on project my-app: Could not resolve dependencies for project com.example:my-app:jar:1.0-SNAPSHOT:
Failed to collect dependencies at com.example:some-library:jar:1.0.0:
Failed to read artifact descriptor for com.example:some-library:jar:1.0.0:
Could not transfer artifact com.example:some-library:pom:1.0.0 from/to central (https://repo.maven.apache.org/maven2):
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project my-app: Compilation failure: Unable to locate the Javac Compiler in: