Maven:JavaFX:在一个Jar文件中捆绑libs

时间:2017-10-25 07:13:42

标签: java eclipse maven javafx

我需要一个解决方案将所有lib文件打包到可执行jar文件中。我使用Maven和Maven插件javafx-maven-pluginmaven-compiler-pluginmaven-surefire-plugin。我还没有根据这些插件找到问题的解决方案。

我希望有人可以帮助我。以下是插件的配置。

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

1 个答案:

答案 0 :(得分:3)

您正在寻找的是超级罐或阴影罐。您可以使用以下maven-plugin:

Maven Shade Plugin

Selecting Contents for Uber JAR