[英]Error: Could not find or load main class in Java Maven project
I am working in Java Maven project.我在 Java Maven 项目中工作。 There is a
.bat
file in the root of the project which invokes a Java class with some arguments something like this:项目的根目录中有一个
.bat
文件,它调用带有一些参数的 Java 类,如下所示:
java my.package.MyClass abc hi 1
Now, my project jar is built in the target directory of that project when I do mvn clean install
.现在,当我执行
mvn clean install
时,我的项目 jar 构建在该项目的目标目录中。 When I run that .bat
file it gives me the below error当我运行那个
.bat
文件时,它给了我以下错误
Error: Could not find or load main class my.package.MyClass
Project's pom.xml
only contains jars as dependency.项目的
pom.xml
仅包含 jar 作为依赖项。
Do I need to do something in pom.xml
to make it work?我需要在
pom.xml
做些什么才能让它工作吗?
please provide your pom.xml
so we can look for it, anyway,请提供您的
pom.xml
以便我们可以查找它,无论如何,
do you use maven-jar-plugin
?你使用
maven-jar-plugin
吗?
something like this像这样的东西
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>your.main.class.package.ClassName</mainClass> // your main class
</manifest>
</archive>
</configuration>
</plugin>
and try to run your *.jar
with command java -jar yourjar.jar
并尝试使用命令
java -jar yourjar.jar
运行您的*.jar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.