如何通过Maven成功构建项目?

huangapple go评论81阅读模式
英文:

How to build the project successfully by maven?

问题

我在GitHub上找到了这个JavaFx项目

我可以运行包含main方法的HelloJavaFxAndMavenApp类,它能够正常工作。

然而,当我尝试使用以下命令通过maven构建项目时,它不起作用:

mvn exec:java -Dexec.mainClass=com.zenjava.examples.hellojfxmaven.HelloJavaFxAndMavenApp

它报错如下:

[ERROR] Unknown lifecycle phase "mvn". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>.
Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [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/LifecyclePhaseNotFoundException
英文:

I found this JavaFx project in GitHub.

I can run the HelloJavaFxAndMavenApp class which contains the main method and it works like a charm.

However, when I try to build the project using maven by the following command it does not work:

mvn exec:java -Dexec.mainClass=com.zenjava.examples.hellojfxmaven.HelloJavaFxAndMavenApp

it complains by:

[ERROR] Unknown lifecycle phase &quot;mvn&quot;. You must specify a valid lifecycle phase or a goal in the format &lt;plugin-prefix&gt;:&lt;goal&gt; or &lt;plugin-group-id&gt;:&lt;plugin-artifact-id&gt;[:&lt;plugin-version&gt;]:&lt;goal&gt;. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -&gt; [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/LifecyclePhaseNotFoundException

答案1

得分: 1

mvn exec:java -Dexec.mainClass=com.zenjava.examples.hellojfxmaven.HelloJavaFxAndMavenApp 在我克隆项目、构建和运行时似乎运行正常。

从错误消息看,似乎存在多余的 mvn(即,您已经运行了 mvn mvn exec:java -Dexec.mainClass=com.zenjava.examples.hellojfxmaven.HelloJavaFxAndMavenApp)。删除重复的 mvn,然后应该没问题。

可能导致这种情况的一个原因是,如果您不是从命令行而是从某个工具/IDE中运行Maven。在这种情况下,该工具本身已经调用了 mvn,只需要提供参数(即,exec:java -Dexec.mainClass=com.zenjava.examples.hellojfxmaven.HelloJavaFxAndMavenApp)。

英文:

mvn exec:java -Dexec.mainClass=com.zenjava.examples.hellojfxmaven.HelloJavaFxAndMavenApp
seems to work just fine when I clone the project, build and run it.

From the error message it looks like you have a redundant mvn there (i.e., you've run mvn mvn exec:java -Dexec.mainClass=com.zenjava.examples.hellojfxmaven.HelloJavaFxAndMavenApp. Remove the duplicate mvn and you should be fine.<br/>
One possible cause for this I could think of is if you're not running Maven from the command line, but from some tool/IDE. In this case, the tool itself already calls mvn and just expects the arguments (i.e., exec:java -Dexec.mainClass=com.zenjava.examples.hellojfxmaven.HelloJavaFxAndMavenApp).

huangapple
  • 本文由 发表于 2020年8月30日 16:22:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/63655437.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定