java 使用 maven 创建 JVM 时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10815944/
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
Error creating JVM using maven
提问by Deep_89
I get an error message Could not create the Java virtual machine
when I do mvn clean install
. What should I do now? Should I change anything in pom.xml
? My java version-1.6 and maven version-3.0.2, all set in pom.xml
Could not create the Java virtual machine
当我这样做时,我收到一条错误消息mvn clean install
。我现在应该怎么办?我应该改变什么pom.xml
吗?我的 java 版本 1.6 和 maven 版本 3.0.2,都设置在pom.xml
Errors are::
错误是::
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] Could not create the Java virtual machine.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.apache.maven.plugins:maven-compiler-plugin:2.3.1:compile (default-compile) on
project accelerator-common: Compilation failure
Failure executing javac, but could not parse the error:
Could not create the Java virtual machine.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBu
ild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
eStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
cher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
352)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation fail
ure
Failure executing javac, but could not parse the error:
Could not create the Java virtual machine.
at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompiler
Mojo.java:656)
at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
BuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:209)
... 19 more
采纳答案by rbento
Are you using it from an IDE like Eclipse or Netbeans?
您是从 Eclipse 或 Netbeans 之类的 IDE 中使用它吗?
If so, you may then:
如果是这样,那么您可以:
- Set the JAVA_HOME to point to your JDK.
- Configure the Maven options in your IDE to use your Maven install instead of the bundled one.
- Configure the Java Runtime to use the JDK instead of the JRE.
- 将 JAVA_HOME 设置为指向您的 JDK。
- 在您的 IDE 中配置 Maven 选项以使用您的 Maven 安装而不是捆绑安装。
- 将 Java 运行时配置为使用 JDK 而不是 JRE。
Configuring the Maven installation in Eclipse
在 Eclipse 中配置 Maven 安装
- Go to Window > Preferences > Maven > Installation.
- Add your Maven installation. Click
Add
and select your Maven install directory. - Select it as your Maven installation.
- 转到窗口 > 首选项 > Maven > 安装。
- 添加您的 Maven 安装。单击
Add
并选择您的 Maven 安装目录。 - 选择它作为您的 Maven 安装。
Configuring the installed JREs option in Eclipse
在 Eclipse 中配置已安装的 JRE 选项
- Go to Window > Preferences > Java > Installed JREs.
- Add a Standard VM that points to your JDK home directory.
- No VM arguments. Of course, if you have any you may add them.
- Mark it as your JRE.
- 转到“窗口”>“首选项”>“Java”>“已安装的 JRE”。
- 添加一个指向 JDK 主目录的标准 VM。
- 没有 VM 参数。当然,如果你有的话,你可以添加它们。
- 将其标记为您的 JRE。
By default Eclipse uses an embedded Maven installation from the Maven plugin and sometimes uses the Non-JDK JRE as the default Java Runtime.
默认情况下,Eclipse 使用来自 Maven 插件的嵌入式 Maven 安装,有时使用非 JDK JRE 作为默认 Java 运行时。
So the steps to make it work is to have a JDK installed, set the JAVA_HOME, unpack Maven to a directory and then in Eclipse change the Maven installation and point the JRE to a JDK JRE.
因此,使其工作的步骤是安装 JDK,设置 JAVA_HOME,将 Maven 解压到一个目录,然后在 Eclipse 中更改 Maven 安装并将 JRE 指向 JDK JRE。
I hope it helps.
我希望它有帮助。
回答by Peter Lawrey
You need to find out why it could not create it. A common reason is that an invalid command line option is used. e.g. M2_OPTS=-Xmx1m
will give you this error.
您需要找出无法创建它的原因。一个常见的原因是使用了无效的命令行选项。例如M2_OPTS=-Xmx1m
会给你这个错误。
回答by cutebug
Please check for the java system properties say -Xmx or -Xms which you specify in mvn clean command. I guess there might be a space between the command and the ram size. i.e you may have specified -Xmx 128rather it should be -Xmx128. It is a wild guess though
请检查您在 mvn clean 命令中指定的 java 系统属性,例如 -Xmx 或 -Xms。我猜命令和内存大小之间可能有空格。即您可能指定了 -Xmx 128而应该是-Xmx128。虽然这是一个疯狂的猜测
回答by rbento
Also match your JAVA_HOME
env variable with JAVA_HOME\bin in PATH
env. It should be of same arch type.
还要将您的JAVA_HOME
env 变量与 env 中的 JAVA_HOME\bin匹配PATH
。它应该是相同的拱形类型。
I faced this problem. I have 16GB ram, and even after setting set MAVEN_OPTS=-Xmx1024m
it did not work after few maven executions and gave errors.
我遇到了这个问题。我有 16GB 内存,即使在设置set MAVEN_OPTS=-Xmx1024m
了几次 Maven后它也不起作用并出现错误。
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.