[英]Can't load main class from java commandline for jar
I have a jar with two main class.我有一个 jar 和两个主要的 class。 I'm trying to run the main class using the command
我正在尝试使用命令运行主 class
java -cp TestNGExamples-0.0.1-SNAPSHOT.jar:lib/* com.test.integration.TestMain
but I get the following error但我收到以下错误
Error: Could not find or load main class com.test.integration.TestMain
I don't want to edit the manifest file since I already have a Main class given there.我不想编辑清单文件,因为那里已经有一个 Main class 。 lib folder is there in the jar and I've checked it.
lib文件夹在 jar 中,我已经检查过了。
Can anyone tell me what I'm doing wrong here?谁能告诉我我在这里做错了什么?
Edit:编辑:
This was my referral: Run a JAR file from the command line and specify classpath这是我的推荐: 从命令行运行 JAR 文件并指定类路径
If I am not wrong you are using maven. If so you can specify your main class in pom.xml.
You can do something like this.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>Main_Class_Package_Name</mainClass>
</manifest>
</archive>
</configuration
</plugin>
</plugins>
</build>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.