Eclipse Maven插件配置问题

8
我已经按照这个帖子的步骤操作了。
现在,当我尝试使用安装的Maven插件进行构建时,出现以下错误。 我执行的目标是clean -X install
Unable to locate the Javac Compiler in:
  C:\Program Files\Java\jre6\..\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.
-> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project trojantime: Compilation failure
Unable to locate the Javac Compiler in:
  C:\Program Files\Java\jre6\..\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.

    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:581)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:324)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:247)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:104)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:427)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:157)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:121)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure
Unable to locate the Javac Compiler in:
  C:\Program Files\Java\jre6\..\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.

    at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:516)
    at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:114)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:105)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:577)
    ... 14 more
[ERROR] 
[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

在首选项中的已安装JRE中,JRE已经被设置。

以下是关于>安装>配置的快照:

*** Platform Details:

*** System properties:
awt.toolkit=sun.awt.windows.WToolkit
com.sun.management.jmxremote=
eclipse.application=org.eclipse.ui.ide.workbench
eclipse.commands=-os
win32
-ws
win32
-arch
x86
-showsplash
D:\eclipse VT preconfigured\eclipse\\plugins\org.eclipse.platform_3.3.202.v201002111343\splash.bmp
-launcher
D:\eclipse VT preconfigured\eclipse\eclipse.exe
-name
Eclipse
--launcher.library
D:\eclipse VT preconfigured\eclipse\plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519\eclipse_1206.dll
-startup
D:\eclipse VT preconfigured\eclipse\plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
-showlocation
-product
org.eclipse.epp.package.jee.product
-vm
c:\Program Files\Java\jdk1.6.0_04\jre\bin\client\jvm.dll
eclipse.home.location=file:/D:/eclipse VT preconfigured/eclipse/
eclipse.launcher=D:\eclipse VT preconfigured\eclipse\eclipse.exe
eclipse.p2.data.area=@config.dir/../p2/
eclipse.p2.profile=epp.package.jee
eclipse.product=org.eclipse.epp.package.jee.product
eclipse.startTime=1279882656890
eclipse.vm=c:\Program Files\Java\jdk1.6.0_04\jre\bin\client\jvm.dll
eclipse.vmargs=-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx740m
-Xss4m
-XX:PermSize=128m
-XX:MaxPermSize=128m
-XX:CompileThreshold=5
-XX:MaxGCPauseMillis=10
-XX:MaxHeapFreeRatio=70
-XX:+UseConcMarkSweepGC
-XX:+CMSIncrementalMode
-XX:+CMSIncrementalPacing
-Dcom.sun.management.jmxremote
-Djava.class.path=D:\eclipse VT preconfigured\eclipse\plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
file.encoding=Cp1252
file.encoding.pkg=sun.io
file.separator=\
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.awt.printerjob=sun.awt.windows.WPrinterJob
java.class.path=D:\eclipse VT preconfigured\eclipse\plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
java.class.version=50.0
java.endorsed.dirs=c:\Program Files\Java\jdk1.6.0_04\jre\lib\endorsed
java.ext.dirs=c:\Program Files\Java\jdk1.6.0_04\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext
java.home=c:\Program Files\Java\jdk1.6.0_04\jre
java.io.tmpdir=C:\DOCUME~1\argus\LOCALS~1\Temp\
java.library.path=D:\eclipse VT preconfigured\eclipse;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;c:/Program Files/Java/jdk1.6.0_04/jre/bin/client;c:/Program Files/Java/jdk1.6.0_04/jre/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\TortoiseSVN\bin;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Java\jdk1.6.0_04\bin;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\Documents and Settings\argus\My Documents\apache-ant-1.7.1-bin\apache-ant-1.7.1\bin;C:\Documents and Settings\argus\My Documents\apache-maven-2.0.10\bin;C:\Documents and Settings\argus\My Documents\groovy-binary-1.7.3\groovy-1.7.3\bin;C:\Documents and Settings\argus\My Documents\patch-2.5.9-7-bin\bin
java.rmi.server.randomIDs=true
java.runtime.name=Java(TM) SE Runtime Environment
java.runtime.version=1.6.0_04-b12
java.specification.name=Java Platform API Specification
java.specification.vendor=Sun Microsystems Inc.
java.specification.version=1.6
java.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi
java.version=1.6.0_04
java.vm.info=mixed mode
java.vm.name=Java HotSpot(TM) Client VM
java.vm.specification.name=Java Virtual Machine Specification
java.vm.specification.vendor=Sun Microsystems Inc.
java.vm.specification.version=1.0
java.vm.vendor=Sun Microsystems Inc.
java.vm.version=10.0-b19
line.separator=
.
.
.

将JDK添加到已安装的JRE中解决了这个问题。谢谢Vineet。 - jmj
是的,这是已安装的JRE。来自eclipse.ini的运行时配置引用了JDK中的jvm.dll,所以这很好。 - Vineet Reynolds
我相信添加JDK正是我在你之前的评论中回答过你的内容,链接为https://dev59.com/W3M_5IYBdhLWcg3wXx1N#1410524,同时也链接到了http://stackoverflow.com/questions/1431531/how-is-the-eclipse-jdk-setting-affecting-the-systems-jdk-setting/1431554#1431554。 - VonC
我认为你会在这里找到答案! https://dev59.com/b2435IYBdhLWcg3w4UMb - user1451161
8个回答

14

看起来Eclipse仍在引用JRE而不是JDK。此外,在Eclipse中默认运行时(在“首选项”对话框的“已安装的运行时”页面中找到)可能是一个JRE。

我注意到这有时是由于多个VM配置被获取,其中应用第一个或最后一个。您可以通过转到Eclipse的关于页面,然后查看安装详细信息中的配置选项卡来确认是否是这种情况(在Helios中)。通常罪魁祸首是eclipse.ini中缺少换行符。


3
也许您正在重复使用一个“运行配置”,而当时JRE是在JDK之外设置的。创建一个新的“运行配置”,确保选项卡指示为Java JDK。

1

尝试将JAVA_HOME设置为JDK,而不是JRE?


1
当你使用Eclipse创建Maven项目时,也许项目属性的文本文件编码和pom.xml中的project.build.sourceEncoding不一致。如果是这种情况,那么在构建项目时会出现错误。
例如,我的文本文件编码是GBK,而project.build.sourceEncoding是UTF-8。我只需将文本文件编码修改为UTF-8,一切都正常了!

0

请注意 -vm 选项的格式 - 精确性非常重要:

-vm 选项及其值(路径)必须位于单独的行上。 该值必须是指向 Java 可执行文件的完整绝对路径,而不仅仅是 Java 安装目录的路径。 -vm 选项必须在 -vmargs 选项之前出现,因为 -vmargs 选项后面的所有内容都会直接传递给 JVM。


0

引用

将JRE转换为JDK:

->进入Windows ->首选项 ->在左上角的搜索框中键入已安装的JRE ->单击已安装的JRE ->从右侧对话框中选择添加 ->单击标准VM ->选择“JREHOME”的目录,然后执行以下操作:“C:\ ProgramFiles \ java \ jdk1.8.0_131” ->然后键入jdk1.8.0_131 “JRE名称” ->单击完成。


0

我之前也遇到了类似的问题。

在我的情况下,发现JAVA_HOME仅在我的用户中定义,而PATH则是为系统设置的。此时maven插件使用默认的JRE而非JDK。 因此,请确保JAVA_HOME和PATH在相同的作用域内(我将这两个变量都设置为系统变量,并将JAVA_HOME作为PATH的第一部分)。

希望能对某些人有所帮助。


0
如果所有的环境都正常,但仍然出现构建错误,那么最后的解决方法是将JAVA_HOME设置为JDK 1.5或更高版本。然后从命令提示符中构建项目。构建应该成功。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接