作为发展我使用 Maven 的技能的一部分,我编译了一个块,多亏了提示,错误消失了。但是当我在终端中运行 java -jar target/JavaStart-1.0-SNAPSHOT-jar-with-dependency.jar 时,出现以下消息:
无法找到或加载主类Main
这是我的 Maven:
<?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>org.example</groupId>
<artifactId>JavaStart</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<archive>
<manifest>
<!-- Замените на ваш класс с методом main -->
<mainClass>Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
请告诉我如何指示正确的路径?
<manifest>
<!-- Замените на ваш класс с методом main -->
<mainClass>Main</mainClass>
</manifest>
我只有一个带有 main 方法的 Main 类。或者路径应该包含计算机上本地文件夹的路径?
<mainClass>Main</mainClass>尝试指示该类的完整位置,例如:<mainClass>org.example.Main</mainClass>package example