6

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

公共静态无效主要(字符串 [] 参数)

我想运行的方法。

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

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

我懂了...

+ 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] ------------------------------------------------------------------------

我尝试过类似的变体

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

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

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

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

我的 pom.xml 中用于 exec-maven-plugin 的片段是......

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

版本在哪里设置<properties>

4

3 回答 3

19

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

于 2011-09-29T20:49:45.193 回答
1

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

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

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

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

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

于 2011-09-28T01:41:38.227 回答
0

只是一个快速清单:

  1. 重命名~/.m2文件夹并mvn exec:java ...再次运行,让 Maven 再次从中央下载所有内容。
  2. 检查您的 exec 插件是否从中央下载。(检查您的本地存储库是否包含与中央存储库相同的文件。)
  3. 在(以及父 pom)中寻找可疑repositorypluginRepository标签。pom.xml
  4. 寻找可疑的repositorypluginRepositorymirror标签中的settings.xml
  5. 在另一台机器上检查项目 - 复制它并尝试在另一台机器上构建/运行 exec:java。
  6. 下载 Maven 3.x 并尝试使用它运行 exec。
于 2011-09-28T19:45:34.277 回答