Maven Unable to locate the Javac Compiler in:

2019-01-30 01:55发布

When i try to generate a war file, it is showing some error like

[ERROR] Unable to locate the Javac Compiler in:
[ERROR] C:\Program Files\Java\jre7\..\lib\tools.jar

When i do echo %path% it shows

 C:\Windows\System32;D:\name\name1\Softwares\Maven\apache-maven-3.0.4\b
in;C:\Program Files\Notepad++\;%JDK_HOME%

When i do echo %JDK_HOME%

D:\name\name\core java\software\Java\Java_1.6.0_04_win\jdk1.6.0_04\bin

I don't know why maven is refering to jre, when my environmental variable is jdk. I also changes installed JRE to jdk1.6.

标签: java maven javac
15条回答
Rolldiameter
2楼-- · 2019-01-30 02:44

In Eclipse, actions like importing Maven projects or invoking "Update Sources" runs in the same JVM in which Eclipse is running. If that JVM comes from JRE that isn’t part of JDK, there would be no Java compiler (the tools.jar).

So to launch Maven from within Eclipse, JRE used for launch also need to come from JDK. By default Eclipse registers JRE it is started in, but this can be configured on "Window / Preferences… / Java / Installed JREs" preference page as mentioned above by Parthasarathy

Alternatively you can specify compilerId in the pom.xml, so Maven won’t be looking for JDK when compiling Java code:

 <plugin>
  <artifactid>maven-compiler-plugin</artifactid>
  <configuration>
    <compilerid>eclipse</compilerid>
  </configuration>
  <dependencies>
    <dependency>
      <groupid>org.codehaus.plexus</groupid>
      <artifactid>plexus-compiler-eclipse</artifactid>
      <version>xxxx</version>
    </dependency>
  </dependencies>
</plugin>
查看更多
该账号已被封号
3楼-- · 2019-01-30 02:45

I have encountered a similar problem, and as no one posted an approach similar to mine, here I go.

Navigate to the run configuration you wanted to launch.
There chose the JRE tab. Adjust the "Runtime JRE" there, and you're ready to go.

查看更多
一纸荒年 Trace。
4楼-- · 2019-01-30 02:48

It depends on of Maven version. When you will install newer version of Maven, this error would not appear. You may also add another directory with tools.jar file lib/tools.jar - it also solve this problem.

查看更多
登录 后发表回答