Java Eclipse Maven 插件配置问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3317402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse Maven Plugin Configuration Problem
提问by Jigar Joshi
I have followed this thread
我已经关注了这个线程
now when i try to build using maven plugin installed i am getting following error.
goal i executed was clean -X install
现在,当我尝试使用安装的 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
in Installed JRE from preferences it is JRE set and
在从首选项安装 JRE 它是 JRE 设置和
here is the snapshot of about>installation>configuration>
这是关于>安装>配置>的快照
*** 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
[email protected]/../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=
.
.
.
采纳答案by Vineet Reynolds
It appears that Eclipse is still referring to a JRE instead of a JDK. Also, the default runtime in Eclipse (found in the "Installed Runtimes" page of the Preferences dialog) might be a JRE.
Eclipse 似乎仍然指的是 JRE 而不是 JDK。此外,Eclipse 中的默认运行时(可在“首选项”对话框的“安装的运行时”页面中找到)可能是 JRE。
I've noticed that this sometimes occurs due to multiple VM configurations being obtained, with the first or the last being applied. You can confirm whether this is the case (in Helios), by going to the About page of Eclipse, and then viewing the Configuration tab in Installation Details. Usually the culprit turns out to be a missing new line in eclipse.ini.
我注意到有时会发生这种情况是因为获得了多个 VM 配置,并且应用了第一个或最后一个。您可以通过转至 Eclipse 的“关于”页面,然后查看“安装详细信息”中的“配置”选项卡来确认是否是这种情况(在 Helios 中)。通常,罪魁祸首是 eclipse.ini 中缺少的新行。
回答by Tushar Tarkas
Try setting JAVA_HOME to JDK and not to JRE ?
尝试将 JAVA_HOME 设置为 JDK 而不是 JRE ?
回答by matali
I had also this kind of problems.
我也遇到过这种问题。
In my case it turned out that JAVA_HOME was defined for my user only while PATH was set for the system and maven plugin used default JRE instead of JDK. So make sure that JAVA_HOME and PATH are in the same scope (I put both variables for system and added JAVA_HOME as the first part in PATH).
就我而言,结果证明 JAVA_HOME 仅在为系统设置 PATH 时为我的用户定义,并且 maven 插件使用默认 JRE 而不是 JDK。因此,请确保 JAVA_HOME 和 PATH 在同一范围内(我为系统放置了两个变量并添加了 JAVA_HOME 作为 PATH 中的第一部分)。
Hope it helps someone.
希望它可以帮助某人。
回答by e-nature
Note the format of the -vm option - it is important to be exact:
请注意 -vm 选项的格式 - 准确很重要:
The -vm option and its value (the path) must be on separate lines. The value must be the full absolute path to the Java executable, not just to the Java home directory. The -vm option must occur before the -vmargs option, since everything after -vmargs is passed directly to the JVM.
-vm 选项及其值(路径)必须在不同的行中。该值必须是 Java 可执行文件的完整绝对路径,而不仅仅是 Java 主目录。-vm 选项必须出现在 -vmargs 选项之前,因为 -vmargs 之后的所有内容都直接传递给 JVM。
回答by z8888q
When you created your Maven project with Eclipse, maybe the text file encoding of your project's properties and the project.build.sourceEncoding
in your pom.xml
were not the same. If that's the case, then when you built the project, you'd get the error
当你创建了Eclipse中的Maven项目,也许是文本文件,你的项目的属性的编码和project.build.sourceEncoding
你pom.xml
是不一样的。如果是这样,那么当你构建项目时,你会得到错误
"Unable to locate the Javac Compiler in:..."
“无法在以下位置找到 Javac 编译器:...”
For example, my text file encoding was GBK, and my project.build.sourceEncoding
was UTF-8. I just modified my text file encoding to UTF-8, and everything was OK!
比如我的文本文件编码是GBK,我的project.build.sourceEncoding
是UTF-8。我刚刚将我的文本文件编码修改为 UTF-8,一切正常!
回答by Herbert
Perhaps you are reusing a "Run configuration" you did when the JRE was set up outside the JDK. Create a new "Run Configuration", making sure that the tab is indicated Java JDK.
也许您正在重用在 JDK 之外设置 JRE 时所做的“运行配置”。创建一个新的“运行配置”,确保该选项卡指示 Java JDK。
回答by venkatram mutyala
If all the environments are fine and you are still getting build errors then the final approach is to set JAVA_HOME
as JDK 1.5 or above. Then build the project from the command prompt. The build should be successful.
如果所有环境都很好并且您仍然遇到构建错误,那么最后的方法是设置JAVA_HOME
为 JDK 1.5 或更高版本。然后从命令提示符构建项目。构建应该成功。
回答by Snehal Masne
You could try updating the JDK Eclipse is using, as follows, and it works:
您可以尝试更新 Eclipse 正在使用的 JDK,如下所示,它可以工作:
Add and set the JRE in Window->Preferences...->Java->Installed JREs:
在 Window->Preferences...->Java->Installed JREs 中添加并设置 JRE:
JRE type: Standard VM JRE
Name: jdk1.6.0_18
JRE home directory: C:\Program Files (x86)\Java\jdk1.6.0_18
If this is not the case, it's possible that the brackets and spaces in the JAVA_HOME path are causing issues. Try copying your JDK to a different location and updating your JAVA_HOME.
如果不是这种情况,则 JAVA_HOME 路径中的括号和空格可能会导致问题。尝试将您的 JDK 复制到其他位置并更新您的 JAVA_HOME。
回答by Chitra Kumar
Blockquote
块引用
TO CONVERT JRE TO JDK:
将 JRE 转换为 JDK:
->Goto windows
->Preferences
->type as installed JRE's
in the left top searchbox
->click installed JRE's
->select add
from the right dialogBox
->click standard vm
->select the directory for "JREHOME" and do the following "C:\ProgramFiles\java\jdk1.8.0_131"
->then type as jdk1.8.0_131
"JRE NAME"
->click finish.
-> 转到窗口 -> 首选项 ->installed JRE's
在左上方的搜索框中键入-> 单击installed JRE's
->add
从右侧对话框中选择-> 单击标准虚拟机 -> 选择“JREHOME”的目录并执行以下操作“C:\ProgramFiles\ java\jdk1.8.0_131”->然后输入jdk1.8.0_131
“JRE NAME”->点击完成。