0

I'd like to create a runnable/executable jar using maven's assembly plugin using the assembly:single goal. (I'm using Eclipse and Java 8, Maven 4) However, only an empty, small size jar created (1 KB or sometimes 2KB) in the target folder. My pom.xml is the following:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Sample</groupId>
    <artifactId>Sample</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging> <!-- Added !!!! -->
    <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>

    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>

        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <!-- Added !!!! Goal assembly:single -->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>controller.Start</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
            <!--  -->

        </plugins>
    </build>
</project>
Thend
  • 95
  • 7
  • What do you get if you run mvn package? – Simon Martinelli Aug 15 '22 at 11:54
  • assembly plugin will ignore test scope dependencies by default. Other than that do you have any classes or resources that should be included or is your src/main folder empty? – SpaceTrucker Aug 15 '22 at 11:57
  • @SimonMartinelli In Eclipse, I clicked on build and gave the goal "package". After, I checked the targer folder and I saw that the jar is bigger now 20KB. On double click, the jar does nothing. I tried to run the jar in console as follows: java -jar Sample.jar I received the following error: no main manifest attribute... After, I opened the jar with WinRAR and added the following line to the manifest file: Main-Class: controller.Start After, I tried to run again, but it gave another error... – Thend Aug 15 '22 at 12:32
  • @SimonMartinelli The error is the following: java.io.FileNotFoundException: C:\Users\Thend\eclipse-workspace\Sample\target\src\main\java\view\Sample.fxml accordingly, it doesn't find the fxml file...so my fxml loader looks like this: URL url = new File("src/main/java/view/Sample.fxml").toURI().toURL(); BorderPane root = (BorderPane)FXMLLoader.load(url); – Thend Aug 15 '22 at 12:32
  • @SpaceTrucker I would like to add everything, do you suggest to use maven-shade-plugin? – Thend Aug 15 '22 at 12:34
  • You cannot load a file like this because it will be packaged in a JAR where the path is differnet – Simon Martinelli Aug 15 '22 at 12:34
  • What are you trying to do? JavaFX? – Simon Martinelli Aug 15 '22 at 12:34
  • @SimonMartinelli Yes, I would like to run a JavaFX app from a jar, only by double clicking on the jar :) – Thend Aug 15 '22 at 12:35
  • Does this answer your question? [Build executable JAR with JavaFX11 from maven](https://stackoverflow.com/questions/57019143/build-executable-jar-with-javafx11-from-maven) – Simon Martinelli Aug 15 '22 at 12:37
  • @SimonMartinelli This is not the same problem at all. Please do not mark as a duplicate. This is a Java 8 (jdk 1.8) project, JavaFX is completely different after Java 9 I have no problem in case of Java 11+ (in other project I use JavaFX with Java18 without a problem) – Thend Aug 15 '22 at 12:42

0 Answers0