Maven 新手,我试图使用 Maven 和 maven-shade-plugin 编译一个项目(因为它似乎是构建一个胖 jar 的最佳插件)。我试图指定我的主类来制作一个可运行的 jar 文件和一些包含翻译字符串的 .properties 文件。
根据 netbeans 输出,编译和构建似乎已通过,但我无法按以下方式运行它(假设由 Maven 构建的 jar 重命名为“程序”):
/usr/bin/java -cp program.jar bot.Main
> could not find or load main class bot.Main
Run Code Online (Sandbox Code Playgroud)
这是我的项目文件结构:
这是我的 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>com.mycompany</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<resources>
<resource>
<directory>src/main/java/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>bot.Main</mainClass>
</manifest>
</archive>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>launcher</shadedClassifierName>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals> …Run Code Online (Sandbox Code Playgroud)