JavaFX maven 程序集警告:“无法包含项目工件...它没有关联的文件或目录”

War*_*kst 3 javafx executable-jar maven

在尝试从运行 Java 1.8.0_121 的基于 JavaFX Maven 的项目创建可执行 jar 时,我使用了以下命令:mvn clean assembly:single。在此过程中,会打印以下警告:

[WARNING] Cannot include project artifact: groupid:artifactid:jar:1.0-SNAPSHOT; it doesn't have an associated file or directory.
Run Code Online (Sandbox Code Playgroud)

生成的 jar 文件已构建,但无法执行。运行时java -jar product.jar,打印出以下错误:

Error: Could not find or load main class groupid.artifactid.MainClass
Run Code Online (Sandbox Code Playgroud)

pom 文件:

<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>groupid</groupId>
    <artifactId>artifactid</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <organization>
        <name>org</name>
    </organization>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <build>
        <finalName>product</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>groupid.artifactid.MainClass</mainClass>
                        </manifest>
                    </archive>
                    <finalName>product</finalName>
                    <appendAssemblyId>false</appendAssemblyId>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

我仔细检查了包结构中是否有一个MainClass.java以入口点命名的类。为什么会发生这种情况以及如何解决?psvmgroupid/artifactid/

War*_*kst 5

我已经通过执行命令解决了该问题

mvn clean compile assembly:single
Run Code Online (Sandbox Code Playgroud)

与之前的不同之处在于增加了目标compile。生成的product.jar文件target/现在可以执行,并且不再打印警告。但是,现在显示不同的警告:

[WARNING] Replacing pre-existing project main-artifact file: /path/to/target/classes with assembly file: /path/to/target/product.jar
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么这有效吗?