windows maven-exec-plugin 无缘无故抛出异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7576265/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:10:20  来源:igfitidea点击:

maven-exec-plugin throws exception for no apparent reason

javawindowsexec-maven-plugin

提问by Chris Phillipson

I type the following in a Windows shell in the root of a Maven project that contains a class with a

我在包含一个类的 Maven 项目的根目录中的 Windows shell 中键入以下内容

public static void main(String[] args)

public static void main(String[] args)

method that I'd like to run.

我想运行的方法。

mvn exec:java -Dexec.mainClass="com.spp.config.main.SqlGeneratorHarness" -e

mvn exec:java -Dexec.mainClass="com.spp.config.main.SqlGeneratorHarness" -e

The class exists and is compiled in that package (i.e., target/classes/com/spp/config/main/SqlGeneratorHarness.class).

该类存在并在该包中编译(即 target/classes/com/spp/config/main/SqlGeneratorHarness.class)。

I see...

我懂了...

+ Error stacktraces are turned on.  
[INFO] Scanning for projects...  
[INFO] Searching repository for plugin with prefix: 'exec'.  
[INFO] ------------------------------------------------------------------------  
[ERROR] BUILD FAILURE  
[INFO] ------------------------------------------------------------------------  
[INFO] Invalid task '.mainClass=com.spp.config.main.SqlGeneratorHarness': you must specify a valid 
       lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal
[INFO] ------------------------------------------------------------------------
[INFO] Trace org.apache.maven.BuildFailureException: Invalid task' .mainClass=com.spp.config.main.SqlGeneratorHarness': you must specify 
       a valid lifecycle phase, or a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor(DefaultLifecycleExecutor.java:1830)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.segmentTaskListByAggregationNeeds(DefaultLifecycleExecutor.java:462)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:175)
       at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
       at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
       at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
       at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
       at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
       at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
       at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Tue Sep 27 14:33:52 PDT 2011
[INFO] Final Memory: 3M/122M
[INFO] ------------------------------------------------------------------------

I've tried variations like

我尝试过类似的变体

mvn exec:exec -Dexec.executable="java" [...]

mvn exec:exec -Dexec.executable="java" [...]

and

mvn org.codehaus.mojo:exec-maven-plugin:1.2.1:java [...]

mvn org.codehaus.mojo:exec-maven-plugin:1.2.1:java [...]

to no avail. What gives?

无济于事。是什么赋予了?

I'm running Maven 2.2.1, Java JDK 1.6.0_27 on Windows 7 Enterprise 64-bit.

我在 Windows 7 Enterprise 64 位上运行 Maven 2.2.1、Java JDK 1.6.0_27。

A snippet from my pom.xml for the exec-maven-plugin is...

我的 pom.xml 中 exec-maven-plugin 的一个片段是......

<plugin> 
   <groupId>org.codehaus.mojo</groupId> 
   <artifactId>exec-maven-plugin</artifactId> 
   <version>${exec-maven-plugin.version}</version> 
</plugin> 

where the version is set in the <properties>

版本设置在 <properties>

回答by Chris Phillipson

So... revisiting this... if you use Windows PowerShell, you will get the exception I originally reported. If, however, you use cmd.exe, then you should be able to run the class with the command as I posted (with or without wrapping double-quotes).

所以......重新审视这个......如果你使用Windows PowerShell,你会得到我最初报告的异常。但是,如果您使用 cmd.exe,那么您应该能够使用我发布的命令运行该类(带或不带双引号)。

回答by Ryan Stewart

There's something very basic going wrong. Try losing the quotation marks. They're not needed there. In fact, try starting with something simpler, like

有一些非常基本的问题。尝试丢失引号。那里不需要它们。事实上,试着从更简单的事情开始,比如

mvn -e exec:java -Dexec.mainClass=foo 

That should give you the error "An exception occured while executing the Java class. foo", and the root cause should be a ClassNotFoundException:

这应该给你错误“执行 Java 类时发生异常。foo”,根本原因应该是 ClassNotFoundException:

Caused by: java.lang.ClassNotFoundException: foo
        at java.net.URLClassLoader.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)

Type it out yourself. Don't copy/paste the command from somewhere else.

自己打出来。不要从其他地方复制/粘贴命令。

回答by palacsint

Just a quick checklist:

只是一个快速清单:

  1. Rename ~/.m2folder and run mvn exec:java ...again and let Maven to download everything again from central.
  2. Check that your exec plugin is downloaded from central. (Check that your local repository contains the same files as the central.)
  3. Looking for suspicious repositoryand pluginRepositorytags in the pom.xml(and parent poms as well).
  4. Looking for suspicious repository, pluginRepositoryand mirrortags in the settings.xml.
  5. Checking the project in an other machine - copy it and try to build/run exec:java in an other machine.
  6. Download Maven 3.x and try to run the exec with it.
  1. 重命名~/.m2文件夹并mvn exec:java ...再次运行,让 Maven 再次从中央下载所有内容。
  2. 检查您的 exec 插件是否是从中央下载的。(检查您的本地存储库是否包含与中央存储库相同的文件。)
  3. 在(以及父 poms 中)寻找可疑repositorypluginRepository标签pom.xml
  4. 寻找可疑的repositorypluginRepositorymirrorsettings.xml.
  5. 在另一台机器上检查项目 - 复制它并尝试在另一台机器上构建/运行 exec:java。
  6. 下载 Maven 3.x 并尝试使用它运行 exec。