提问者:小点点

在jpack中复制Maven依赖文件和运行时


我有一个JavaFX项目,依赖于SQLitePOI,所以我使用maven-依赖-插件将所有依赖复制到target\lib文件夹中。该文件夹包含大约21个依赖项公共编解码器,curvesapi,javafx-base,javafx-fxml…等。

要创建一个jpack,我使用jpackage-maven-plugin创建一个安装程序。我将jmods文件夹复制到java. home。POM如下:

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>19</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>19</version>
        </dependency>
        <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.39.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>5.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>5.2.3</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.4.0</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib/</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <configuration>
                    <launcher>App</launcher>
                    <mainClass>com.example.App</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>com.example.App</mainClass>
                        </configuration>
                    </execution>
                    <execution>
                        <id>debug</id>
                        <configuration>
                            <options>
                                <option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:8000</option>
                            </options>
                        </configuration>
                    </execution>
                    <execution>
                        <id>ide-debug</id>
                        <configuration>
                            <options>
                                <option>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</option>
                            </options>
                        </configuration>
                    </execution>
                    <execution>
                        <id>ide-profile</id>
                        <configuration>
                            <options>
                <option>${profiler.jvmargs.arg1}</option>
                <option>${profiler.jvmargs.arg2}</option>
                <option>${profiler.jvmargs.arg3}</option>
                <option>${profiler.jvmargs.arg4}</option>
                <option>${profiler.jvmargs.arg5}</option>
                            </options>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.panteleyev</groupId>
                <artifactId>jpackage-maven-plugin</artifactId>
                <version>1.6.0</version>
                <configuration>
                    <name>ExampleFX</name>
                    <appVersion>${project.version}</appVersion>
                    <icon>${basedir}/icon.ico</icon>
                    <vendor>Myself</vendor>
                    <destination>Runtime</destination>
                    <modulePaths>
                        <modulePath>C:\Program Files\Java\jmods</modulePath>
                        <modulePath>${project.build.directory}/classes</modulePath>
                    </modulePaths>
                    <module>com.example/com.example.App</module>
                    <runtimeImage>${java.home}/lib</runtimeImage>
                    <winDirChooser>true</winDirChooser>
                    <winShortcut>true</winShortcut>
                    <winConsole>true</winConsole>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <release>19</release>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

此命令既不会在安装程序中打包lib文件夹,也不会正确复制JVM,因为在运行程序时,它会在"C:\Program Files\example\runtime"目录中给出无法找到JVM。错误。感谢任何帮助。

编辑

更改了一些参数:

从<代码>

添加模块路径

现在应用程序无法找到${INSTALLDIR}/app/mods中存在的模块(依赖项)。尝试添加这些模块需要我删除runtimeImage参数。如果我这样做:

<addModules>javafx.fxml,javafx.controls,
org.apache.poi.ooxml,org.apache.poi.poi,org.xerial.sqlitejdbc,SparseBitSet,
org.apache.commons.compress,org.apache.commons.codec,org.apache.commons.collections4,
org.apache.commons.io,com.github.virtuald.curvesapi,commons.math3,
org.apache.commons.collections4,org.apache.xmlbeans</addModules>

我总是得到错误关于任何模块随机:jlink失败:错误:自动模块不能与jlink使用:公共. math3从文件:///C:/用户/MY/文档/NetBeansProjects/示例/目标/lib/公共事务-math3-3.6.1。jar

模块信息

module com.example{
    requires javafx.controls;
    requires javafx.fxml;
    requires javafx.base;
    requires javafx.graphics;
    requires java.logging;
    requires java.base;
    requires java.sql;
    requires org.apache.poi.poi;
    requires org.apache.poi.ooxml;
    requires org.apache.commons.codec;
    requires org.apache.commons.collections4;
    requires org.apache.commons.compress;
    requires org.apache.commons.io;
    requires commons.math3;
    requires com.github.virtuald.curvesapi;
    requires org.apache.logging.log4j;
    requires SparseBitSet;
    requires org.xerial.sqlitejdbc;
    requires org.apache.xmlbeans;
    
    opens com.example to javafx.fxml;
    exports com.example;
}

共1个答案

匿名用户

使用JPackageScriptFX。以下是如何使用它:

(我会将JPackageScriptFX称为JPS,将您的项目称为示例

  1. 将您的示例项目文件夹复制到JPS的文件夹中。
  2. 打开JPS的POM,然后转到
package com.example
public class AppLauncher{
    public static void main(String[] args){
        App.main(args);
    }
}