Lars
Lars

Reputation: 173

Maven: JavaFX: Bundle libs in one Jar File

I need a solution to pack all lib-files into the executable jar-file.I use Maven and the Maven plugins javafx-maven-plugin, maven-compiler-plugin and maven-surefire-plugin. I haven't found a solution for my problem based on these plugins yet.

I hope someone can help me. Here are the configurations of the plugins.

<build>
    <plugins>
        <!-- https://github.com/javafx-maven-plugin/javafx-maven-plugin -->
        <plugin>
            <groupId>com.zenjava</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>8.1.4</version>
            <configuration>
                <mainClass>${exec.mainClass}</mainClass>
                <verbose>true</verbose>
                <jfxAppOutputDir>${project.basedir}/target/output</jfxAppOutputDir>
                <jfxMainAppJarName>${project.name}.jar</jfxMainAppJarName>
                <allPermissions>true</allPermissions>
                <manifestAttributes>
                    <Specification-Title>${project.name}</Specification-Title>
                    <Specification-Version>${project.version}</Specification-Version>
                    <Specification-Vendor>${project.organization.name}</Specification-Vendor>
                    <Implementation-Title>${project.name}</Implementation-Title>
                    <Implementation-Version>${build.number}</Implementation-Version>
                    <Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
                    <Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
                    <Implementation-URL>${project.organization.url}</Implementation-URL>
                </manifestAttributes>
            </configuration>
            <executions>
                <execution>
                    <id>create-jfxjar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>build-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <compilerArguments>
                    <bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <configuration>
                <skipTests>false</skipTests>
                <properties>
                    <property>
                        <name>listener</name>
                        <value>org.sonar.java.jacoco.JUnitListener</value>
                    </property>
                </properties>
            </configuration>
        </plugin>
    </plugins>
</build>

Upvotes: 0

Views: 560

Answers (1)

Olof Kohlhaas
Olof Kohlhaas

Reputation: 130

What you are looking for is called uber-jar or shaded jar. You can use the following maven-plugin:

Maven Shade Plugin

Selecting Contents for Uber JAR

Upvotes: 3

Related Questions