【问题标题】:How to use Maven exec plugin in Eclipse?如何在 Eclipse 中使用 Maven 执行插件?
【发布时间】:2015-06-11 19:34:21
【问题描述】:

我是 Maven 新手,我正在尝试使用 exec:java 运行一个项目。我的构建失败了,大概是因为我没有 exec 插件。我下载了插件 (http://mvnrepository.com/artifact/org.codehaus.mojo/exec-maven-plugin),但现在我不知道如何处理它才能在 Eclipse 中使用它。我尝试将其添加到构建路径中,但这似乎不起作用。这可能是一个非常愚蠢的问题,但是我该如何让插件工作呢?

这是我的构建输出:

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Twitter2 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- exec-maven-plugin:1.4.0:java (default-cli) @ Twitter2 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.826 s
[INFO] Finished at: 2015-06-11T14:24:29-06:00
[INFO] Final Memory: 10M/114M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java (default-cli) on project Twitter2: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java are missing or invalid -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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/PluginParameterException

【问题讨论】:

    标签: eclipse maven plugins exec


    【解决方案1】:

    正如错误所说,似乎 mainClass 参数,它告诉插件要运行什么类,设置不正确。有关插件的 java 目标的用法,请参见 http://www.mojohaus.org/exec-maven-plugin/java-mojo.html。尝试在 POM 配置中添加参数:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <configuration>
             <mainClass>fully.qualified.class.name</mainClass>
        </configuration>
    </plugin>
    

    或者通过命令行中的属性-Dexec.mainClass=fullClassName

    【讨论】:

    • 感谢您的回复。我似乎无法弄清楚如何正确编写完全限定的类名。你能概括一下吗?
    • @user 见docs.oracle.com/javase/tutorial/java/package/index.html。它应该取决于包名称。例如,如果您的类MyClass 在源目录src 下,特别是在包文件夹a/b/c 下,则完全限定名称将是a.b.c.MyClass
    • 我让它运行了,但它给出了这个警告:[WARNING] Some problems were encountered while building the effective model for Test:Twitter2:jar:0.0.1-SNAPSHOT [WARNING] 'build.plugins.plugin.version' for org.codehaus.mojo:exec-maven-plugin is missing. @ line 19, column 14这是我需要解决的问题吗?
    • 这只是一个警告。但是您可以通过添加插件版本来摆脱它,在这种情况下,&lt;version&gt;1.4.0&lt;/version&gt; 在 POM 的插件配置中(1.4.0 是 Maven 使用的版本,如您的构建输出所示)。
    • 非常感谢!现在我的程序可以正常运行了。
    猜你喜欢
    • 2011-02-18
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多