RDM
RDM

Reputation: 5066

JavaFX maven assembly warning: "Cannot include project artifact ... it doesn't have an associated file or directory"

In an attempt to create an executable jar from a JavaFX Maven-based project running Java 1.8.0_121, I was using the command: mvn clean assembly:single. During the process, the following warning is printed:

[WARNING] Cannot include project artifact: groupid:artifactid:jar:1.0-SNAPSHOT; it doesn't have an associated file or directory.

The resulting jar file was built but it could not be executed. When running java -jar product.jar, the following error was being printed:

Error: Could not find or load main class groupid.artifactid.MainClass

The pom file:

<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>

I double checked that there is a class named MainClass.java with a psvm entry point in the package structure groupid/artifactid/. Why is this happening and how can it be resolved?

Upvotes: 3

Views: 2850

Answers (1)

RDM
RDM

Reputation: 5066

I've resolved the issue by executing the command

mvn clean compile assembly:single

The difference with before is the added goal compile. The resulting product.jar file in target/ is now executable and the warning is no longer printed. However, a different warning is now shown:

[WARNING] Replacing pre-existing project main-artifact file: /path/to/target/classes with assembly file: /path/to/target/product.jar

Can someone explain why this works?

Upvotes: 5

Related Questions