Maven Error - Fatal error compiling: tools.jar not found

오류 내용

STS(Spring Tool Suite)에서 Spring Maven project를 Maven cealn install 명령으로 빌드를 했는데 아래와 같이 빌드가 실패했다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom
[INFO] Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom (7 KB at 4.0 KB/sec)
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mokaboard ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mokaboard ---
[WARNING] Using platform encoding (MS949 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ mokaboard ---
[WARNING] File encoding has not been set, using platform encoding MS949, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\amagr\Desktop\projectes\MokaBoard\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.644 s
[INFO] Finished at: 2018-07-07T17:57:37+09:00
[INFO] Final Memory: 10M/114M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project mokaboard: Fatal error compiling: tools.jar not found: C:\Program Files\Java\jre1.8.0_171\..\lib\tools.jar -> [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/MojoExecutionException

핵심 오류 내용은 아래인것 같다. 해결방법을 검색해 보자...

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project mokaboard: Fatal error compiling: tools.jar not found: C:\Program Files\Java\jre1.8.0_171..\lib\tools.jar

결국 Maven 빌드하는데 tools.jar를 못찾겠다고 하는 것이다.

해결방법

STS에서 프로젝트의 properties에 들어간다. Java Build Path -> Libraries 탭에서 JRE System Library를 클릭하고 Edit 버튼을 클릭.

Installed JREs를 클릭.

JRE를 선택하고 Edit 클릭.

Add External Jars를 클릭.

java가 설치된 경로에서 jdk/lib로 이동후 tools.jar를 선택 후 열기 클릭.

방금 선택된 tools.jar가 추가된 것을 확인!.

이제 Maven clean install을 하면 성공적으로 Maven 빌드가 실행된다.