抱歉另一个“无法找到或加载主类”的问题。我是 Java 新手。我搜索了一段时间,但找不到原因。我的项目是一个非常简单的项目,使用maven.mvn archetype:generate -DgroupId=mycompany -DartifactId=faker -DinteractiveMode=falsepom.xml(默认,不变)<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>mycompany</groupId> <artifactId>faker</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>faker</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies></project>和源代码(默认,不变)package mycompany;public class App { public static void main( String[] args ) { System.out.println( "Hello World!" ); }}我用jar命令构建 jar 文件。~$ jar cvfm MyCompany.jar manifest.txt src/main/java/mycompany/App.java# added manifest# adding: src/main/java/mycompany/App.java(in = 705) (out= 352)(deflated 50%)清单.txt~$ cat manifest.txt Main-Class: mycompany.App# (has an empty new line here)但是每当我执行它时,它都会给我以下错误:~$ java -jar MyCompany.jar Error: Could not find or load main class mycompany.App哪里错了?openjdk version "1.8.0_181"Apache Maven 3.5.2感谢@ohlec 和@Kayaman,更具体地说,这是解决它的方法。# get App.class~$ cd src/main/java/mycompany/ && javac App.java# back to faker folder~$ jar cvfm MyCompany.jar manifest.txt -C src/main/java mycompany/App.class~$ java -jar MyCompany.jar# Hello World!
添加回答
举报
0/150
提交
取消