【问题标题】:Maven: JavaFX: Bundle libs in one Jar FileMaven:JavaFX:将库捆绑在一个 Jar 文件中
【发布时间】:2018-04-06 04:12:11
【问题描述】:

我需要一个解决方案来将所有 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>

【问题讨论】:

  • 你不使用javapackager吗?
  • 我只使用mvn clean package

标签: java eclipse maven javafx


【解决方案1】:

您要查找的内容称为 uber-jar 或 shaded jar。您可以使用以下 maven-plugin:

Maven Shade Plugin

Selecting Contents for Uber JAR

【讨论】:

  • 使用 javapackager AFAIK。很好。
  • 我找到了maven-assembly-plugin 的解决方案,但谢谢:+1:
  • Maven Shade Plugin 应该是要走的路。易于设置。欲了解更多信息,请参阅stackoverflow post
猜你喜欢
  • 2016-10-17
  • 2011-01-09
  • 2013-04-10
  • 2019-07-24
  • 1970-01-01
  • 2011-01-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多