java - Maven:JavaFX:将库捆绑在一个 Jar 文件中

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

最佳答案

您正在寻找的东西称为 uber-jar 或 Shadowd jar。您可以使用以下 maven-plugin:

Maven Shade Plugin

Selecting Contents for Uber JAR

关于java - Maven:JavaFX:将库捆绑在一个 Jar 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46926181/

相关文章:

java - POJO 属性的 GSON 映射空值

java - 填充内存数据网格 Hazelcast 的最快方法

java - 通过代码动态在eclipse中创建一个JAR文件

java - Android 错误 : type mismatch cannot convert from android. app.actionbar 到 android.support.v7.app.actionbar

maven - maven 编译器 :compile works, maven 编译不

maven - 分步说明设置 SoapUI 项目以使用 Maven 作为 CI 的一部分运行

java - 我对 switch 语句的理解有什么问题?

java - Volley 不从 https 服务器检索图像

java - Spring Boot Maven - 无法将 Web 应用程序打包为可执行 jar/war

java - 如何使用lint4j插件进行Gradle构建以及如何为Jenkins配置它?