使用参数从命令行运行java Maven项目时出错
我有一个Maven项目,其文件结构如下:
src/main/java/com/TestFolder/{Java file name}
这个Java文件包含一个main方法,我需要使用命令行中的参数执行该方法。如何做到这一点?请帮忙
目前我正在做这样的事情:
mvn exec:java -Dexec.mainClass=src.main.java.com.TestFolder.MyMainJavaClass -Dexec.args="1"
这是正确的语法吗?因为当我运行此命令时,会出现以下错误:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven- plugin:1.4.0:java (default-cli) on project Staples_7Lakh: Execution default-cli of goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java failed: Plugin org.codehaus.mojo:exec-maven-plugin:1.4.0 or one of its dependencies could not be resolved: The following artifacts could not be resolved: backport-util-concurrent:backport-util-concurrent:jar:3.1, org.apache.maven:maven-core:jar:2.2.1, org.codehaus.plexus:plexus-utils:jar:3.0.20: Could not transfer artifact backport-util-concurrent:backport-util-concurrent:jar:3.1 from/to central (https://repo.maven.apache.org/maven2): GET request of: backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar from central failed: SSL peer shut down incorrectly -> [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/PluginResolutionException
# 1 楼答案
这个问题是因为可执行jar中缺少依赖项。可执行jar需要存在所有运行时依赖项。我还遇到了一个类似的问题,我使用maven assembly plugin解决了这个问题。请在下面的配置中找到组装插件配置的pom文件-
溴