[英]“Could not find or load main class” when running a jar file from a msf4j project
I'm working on a Java project which uses the msf4j library. 我正在使用msf4j库的Java项目中工作。 In IntelliJ IDEA I'm able to run the project, everything works as expected.
在IntelliJ IDEA中,我能够运行项目,一切都按预期工作。 However, If I build a jar file from this project (aplying the first part of this answer), the jar file cannot run (using
java -jar my_jar.jar
). 但是,如果我从该项目构建一个jar文件(使用此答案的第一部分),则该jar文件将无法运行(使用
java -jar my_jar.jar
)。 It says: 它说:
Error: Could not find or load main class Main
错误:找不到或加载主类Main
I've cleaned the project several times, restarted everything, even tried to use older versions of the msf4j, nothing has helped. 我已经多次清理了该项目,重新启动了所有程序,甚至尝试使用旧版本的msf4j,但没有任何帮助。 If I replace the msf4j with something else (eg javalin ), the built jar file is runnable, the problem goes away.
如果我用其他东西(例如javalin )替换msf4j,则生成的jar文件是可运行的,问题就消失了。
pom.xml: pom.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.group.id</groupId>
<artifactId>my_artifact</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.wso2.msf4j</groupId>
<artifactId>msf4j-core</artifactId>
<version>2.5.2</version>
</dependency>
</dependencies>
<properties>
<microservice.mainClass>src.main.java.Main</microservice.mainClass>
</properties>
</project>
MANIFEST.MF: MANIFEST.MF:
Manifest-Version: 1.0
Main-Class: Main
I think the problem is somewhere in the msf4j artifacts. 我认为问题出在msf4j工件中。 Any idea how to fix this problem?
任何想法如何解决此问题?
from the top of my head I thing you need to set in maven a project parent and remove the dependency. 从我的头顶开始,我需要在maven中设置项目父级并删除依赖项。
<parent>
<groupId>org.wso2.msf4j</groupId>
<artifactId>msf4j-service</artifactId>
<version>2.5.2</version>
</parent>
HTH, Gal HTH,Gal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.