[英]Running Java project through command line (with Maven dependencies)
I want to run my working Java project through my terminal (mac). 我想通过终端(mac)运行可运行的Java项目。 It uses Maven to pull in required dependencies.
它使用Maven引入所需的依赖关系。 Any help would be very much appreciated.
任何帮助将不胜感激。
First I ran the commend: mvn clean install
首先,我运行了该命令:
mvn clean install
Next: mvn dependency:copy-dependencies
下一页:
mvn dependency:copy-dependencies
Finally: cd target/ java -cp MyProject-1.0-SNAPSHOT.jar:dependency Main
最后:
cd target/ java -cp MyProject-1.0-SNAPSHOT.jar:dependency Main
Unfortunately the following error is thrown (clearly showing the dependencies are not being used correctly): 不幸的是,抛出了以下错误(清楚地显示依赖关系未正确使用):
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/parser/JSONParser at Main$Quote.quoteMachine(Hi.java:21) at Main.main(Hi.java:12) Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.JSONParser
... Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/parser/JSONParser at Main$Quote.quoteMachine(Hi.java:21) at Main.main(Hi.java:12) Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.JSONParser
...
I managed to solve the problem by adding this to my POM file: 通过将其添加到我的POM文件中,我设法解决了这个问题:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
After this I simply ran the following commands in my terminal: 之后,我只需在终端中运行以下命令:
mvn clean install
And then: 接着:
mvn exec:java
您需要在类路径中包含json-simple-.jar
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.