分发使用自动模块的JavaFX应用程序 [英] Distributing JavaFX Applications that use automodules

查看:73
本文介绍了分发使用自动模块的JavaFX应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了JavaFX应用程序.它可以在我的Intellij IDE中完美运行.现在,我想分发该应用程序-即,我想获得一个用户可以下载的安装程序,然后它将为他们安装该应用程序.

我发现了有关此

pom.xml:

 < project xmlns ="http://maven.apache.org/POM/4.0.0&";xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"< modelVersion> 4.0.0</modelVersion>< groupId> com.company</groupId>< artifactId> TestApp</artifactId>< version> 1.0-SNAPSHOT</version><属性>< project.build.sourceEncoding> UTF-8</project.build.sourceEncoding>< maven.compiler.source> 15</maven.compiler.source>< maven.compiler.target> 15</maven.compiler.target></properties><依赖关系><依赖关系>< groupId> org.openjfx</groupId>< artifactId> javafx-controls</artifactId>< version> 15.0.1</version></dependency><依赖关系>< groupId> org.openjfx</groupId>< artifactId> javafx-fxml</artifactId>< version> 15.0.1</version></dependency><依赖关系>< groupId> de.jensd</groupId>< artifactId> fontawesomefx-fontawesome</artifactId>< version> 4.7.0-9.1.2</version></dependency><依赖关系>< groupId> org.xerial</groupId>< artifactId> sqlite-jdbc</artifactId>< version> 3.34.0</version></dependency><依赖关系>< groupId> org.apache.commons</groupId>< artifactId> commons-lang3</artifactId>< version> 3.12.0</version></dependency><依赖关系>< groupId> com.itextpdf</groupId>< artifactId>内核</artifactId>< version> 7.1.14</version></dependency><依赖关系>< groupId> com.itextpdf</groupId>< artifactId>布局</artifactId>< version> 7.1.14</version></dependency><依赖关系>< groupId> com.itextpdf</groupId>< artifactId> io</artifactId>< version> 7.1.14</version></dependency><依赖关系>< groupId> org.slf4j</groupId>< artifactId> slf4j-jdk14</artifactId>< version> 1.7.30</version></dependency></dependencies>< build>< plugins>< plugin>< groupId> org.apache.maven.plugins</groupId>< artifactId> maven-compiler-plugin</artifactId>< version> 3.8.0</version><配置>< release> 15</release>< source> 15</source>< target> 15</target></configuration></plugin>< plugin>< groupId> org.openjfx</groupId>< artifactId> javafx-maven-plugin</artifactId>< version> 0.0.5</version><配置>< mainClass> com.company.TestApp</mainClass></configuration></plugin></plugins></build></project> 

module-info.java:

  module com.company {需要javafx.controls;需要javafx.fxml;需要java.sql;需要org.apache.commons.lang3;需要内核;需要布局;需要io;需要sqlite.jdbc;需要javafx.graphics;将com.company打开到javafx.fxml;打开com.company.controllers到javafx.fxml;出口公司出口com.company.controllers;} 

TestAppController.java:

 包com.company.controllers;导入javafx.event.ActionEvent;导入javafx.fxml.FXML;导入javafx.scene.control.Button;导入javafx.scene.control.TextArea;导入org.apache.commons.lang3.StringUtils;导入com.itextpdf.kernel.pdf.PdfDocument;导入com.itextpdf.kernel.pdf.PdfWriter;导入com.itextpdf.layout.element.Paragraph;导入com.itextpdf.layout.Document;导入java.io.FileNotFoundException;公共类TestAppController {@FXML私有TextArea taText;@FXML私人按钮btnPrint;公共无效handleButtonAction(ActionEvent事件){如果(event.getSource()== btnPrint){setTaText();printPdf();}}公共无效setTaText(){taText.setText(StringUtils.leftPad(随机文本左侧填充50",50));}公共无效printPdf(){字符串目录字符串="src/main/resources/com/company/pdf";尝试 {字符串filepath = directoryString +"/";+" pdf_1"+".pdf";PdfWriter writer =新的PdfWriter(filepath);PdfDocument pdf =新的PdfDocument(writer);文件文件=新文件(pdf);document.add(new Paragraph(taText.getText()));document.close();} catch(FileNotFoundException e){System.out.println(e.getMessage());返回;}}} 

TestApp.java:

  package com.company;导入javafx.application.Application;导入javafx.fxml.FXMLLoader;导入javafx.scene.Parent;导入javafx.scene.Scene;导入javafx.stage.Stage;公共类TestApp扩展了应用程序{公共静态void main(String [] args){发射(参数);}public void start(Stage primaryStage)引发异常{父根= FXMLLoader.load(getClass().getResource("testApp.fxml")));场景场景=新场景(根);primaryStage.setScene(scene);primaryStage.setTitle("Test");primaryStage.show();}} 

testApp.fxml:

 <?xml version ="1.0"encoding ="UTF-8"?<?import javafx.scene.control.Button?><?import javafx.scene.control.TextArea?><?import javafx.scene.layout.AnchorPane吗?<?import javafx.scene.layout.BorderPane?><?import javafx.scene.text.Font?>< BorderPane maxHeight =-Infinity";maxWidth =-无穷大".minHeight =-无穷大".minWidth =-无穷大".prefHeight ="400.0&";prefWidth ="600.0&".xmlns ="http://javafx.com/javafx/15.0.1"xmlns:fx =" http://javafx.com/fxml/1";fx:controller =" com.company.controllers.TestAppController">< top>< AnchorPane prefHeight ="60.0&";prefWidth ="600.0&".style ="-fx-background-color:#337DFF;"BorderPane.alignment ="CENTER"/></top>< center>< AnchorPane prefHeight ="200.0&";prefWidth ="200.0&";BorderPane.alignment ="CENTER"< children><按钮fx:id ="btnPrint";layoutX ="240.0&"layoutY ="155.0&".mnemonicParsing ="false".onAction ="#handleButtonAction"prefHeight ="25.0".prefWidth ="120.0&".style ="-fx-background-color:#337DFF;"text =打印PDF"textFill ="WHITE"< font><字体名称=系统粗体";尺寸="15.0"/></font></按钮>< TextArea fx:id =" taText"layoutX ="125.0&"layoutY ="44.0&".prefHeight ="82.0".prefWidth ="350.0&";/></children></AnchorPane></center></BorderPane> 

解决方案

您可以使用moditect插件代替javafx maven插件来创建缺少的module-info来自动依赖模块,然后使用moditect构建映像.

像这样的pom可能是这样的:

 <?xml version ="1.0"encoding ="UTF-8"?< project xmlns ="http://maven.apache.org/POM/4.0.0&";xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation ="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"< modelVersion> 4.0.0</modelVersion>< groupId> com.company</groupId>< artifactId> TestApp</artifactId>< version> 1.0-SNAPSHOT</version><属性>< appName> TestApp</appName>< launcherName> testapp</launcherName>< moduleName> com.company</moduleName>< mainClass> com.company.LoginApp</mainClass>< project.build.sourceEncoding> UTF-8</project.build.sourceEncoding>< maven.compiler.source> 15</maven.compiler.source>< maven.compiler.target> 15</maven.compiler.target>< version.java> 15</version.java></properties><依赖关系><依赖关系>< groupId> org.openjfx</groupId>< artifactId> javafx-controls</artifactId>< version> 15.0.1</version></dependency><依赖关系>< groupId> org.openjfx</groupId>< artifactId> javafx-fxml</artifactId>< version> 15.0.1</version></dependency><依赖关系>< groupId> de.jensd</groupId>< artifactId> fontawesomefx-fontawesome</artifactId>< version> 4.7.0-9.1.2</version></dependency><依赖关系>< groupId> org.xerial</groupId>< artifactId> sqlite-jdbc</artifactId>< version> 3.34.0</version></dependency><依赖关系>< groupId> org.apache.commons</groupId>< artifactId> commons-lang3</artifactId>< version> 3.12.0</version></dependency><依赖关系>< groupId> com.itextpdf</groupId>< artifactId>内核</artifactId>< version> 7.1.14</version></dependency><依赖关系>< groupId> com.itextpdf</groupId>< artifactId>布局</artifactId>< version> 7.1.14</version></dependency><依赖关系>< groupId> com.itextpdf</groupId>< artifactId> io</artifactId>< version> 7.1.14</version></dependency><依赖关系>< groupId> org.slf4j</groupId>< artifactId> slf4j-api</artifactId>< version> 1.7.30</version></dependency></dependencies>< build>< plugins>< plugin>< groupId> org.apache.maven.plugins</groupId>< artifactId> maven-compiler-plugin</artifactId>< version> 3.8.1</version><配置>< release> $ {version.java}</release></configuration></plugin>< plugin>< groupId> org.apache.maven.plugins</groupId>< artifactId> maven-dependency-plugin</artifactId>< version> 3.1.2</version><执行><执行>< id>复制依赖性</id>< phase>包装</phase><目标>< goal>复制依赖性</goal></goals><配置>< outputDirectory> $ {project.build.directory}/modules</outputDirectory>< overWriteReleases> false</overWriteReleases>< overWriteSnapshots> false</overWriteSnapshots>< overWriteIfNewer> true</overWriteIfNewer></configuration></execution></executions></plugin>< plugin>< groupId> org.moditect</groupId>< artifactId> moditect-maven-plugin</artifactId>< version> 1.0.0.RC1</version><执行><执行>< id>向依赖项添加模块信息</id>< phase>包装</phase><配置>< outputDirectory> $ {project.build.directory}/modules</outputDirectory>< overwriteExistingFiles> true</overwriteExistingFiles><模块><模块>< artifact>< groupId> com.itextpdf</groupId>< artifactId>内核</artifactId></artifact>< moduleInfo><名称>内核</名称></moduleInfo></module><模块>< artifact>< groupId> com.itextpdf</groupId>< artifactId>布局</artifactId></artifact>< moduleInfo>< name>布局</name></moduleInfo></module><模块>< artifact>< groupId> com.itextpdf</groupId>< artifactId> io</artifactId></artifact>< moduleInfo>< name> io</name></moduleInfo></module><模块>< artifact>< groupId> org.xerial</groupId>< artifactId> sqlite-jdbc</artifactId></artifact>< moduleInfo>< name> sqlite.jdbc</name></moduleInfo></module><模块>< artifact>< groupId> org.apache.commons</groupId>< artifactId> commons-lang3</artifactId></artifact>< moduleInfo>< name> org.apache.commons.lang3</name></moduleInfo></module><模块>< artifact>< groupId> org.slf4j</groupId>< artifactId> slf4j-api</artifactId></artifact>< moduleInfo>< name> org.slf4j</name></moduleInfo></module></modules><模块>< mainClass> $ {mainClass}</mainClass>< moduleInfoFile> $ {project.build.sourceDirectory}/module-info.java</moduleInfoFile></module>< jdepsExtraArgs>< args>-多次发布</args>< args> 15</args>< args> --ignore-missing-deps</args></jdepsExtraArgs></configuration><目标>< goal>添加模块信息</goal></goals></execution><执行>< id>创建运行时图像</id>< phase>包装</phase><目标>< goal> create-runtime-image</goal></goals><配置>< modulePath>< path> $ {project.build.directory}/modules</path></modulePath><模块>< module> $ {moduleName}</module></modules>< launcher>< name> $ {launcherName}</name>< module> $ {moduleName}</module></launcher>< compression> 2</compression>< stripDebug> true</stripDebug>< outputDirectory> $ {project.build.directory}/jlink-image</outputDirectory>< ignoreSigningInformation> true</ignoreSigningInformation></configuration></execution></executions></plugin>< plugin>< groupId> com.github.akman</groupId>< artifactId> jpackage-maven-plugin</artifactId>< version> 0.1.2</version><执行><执行>< phase>包装</phase><目标>< goal> jpackage</goal></goals><配置>< name> $ {appName}</name>< type>图像</type>< runtimeimage> $ {project.build.directory}/jlink-image</runtimeimage>< module> $ {moduleName}/$ {mainClass}</module></configuration></execution></executions></plugin></plugins></build></project> 

我的第一个测试似乎很成功,但是有些项目可能需要做更多的工作(例如,我不喜欢使用--ignore-missing-deps参数)

也许这可以帮助您前进.

I have created a JavaFX application. It runs perfectly in my Intellij IDE. Now I want to distribute the application - i.e. I want to obtain an installer that users could download and then it would install the application for them.

I found a very interesting article about this here. This blog article basically describes what I want to achieve. There are two differences though:

  1. I am using Maven and not Gradle

  2. I have dependencies which use automodules such as iText7 and apache.commons.lang3

The usage of automodules is making things very complicated. There is a GitHub project called ModiTect (here) that has been written to solve these issues. I have no experience in using ModiTect though and even my Maven knowledge is barely existent (meaning: I don't really know what I am doing in the pom.xml).

What I am looking for is an explanation (step-by-step) as on how to integrate ModiTect (and if necessary jpackage) into my pom.xml in order to obtain an installer for my JavaFX application that uses automodules (and also a sqlite database, which shouldn't be a problem though).

Can somebody provide this explanation or refer me to a tutorial?

I provide a MWE at the end of this question. The MWE ist a TestApp. To illustrate the problem, run the application and press the "Print PDF" button. A pdf is created in resources --> pdf

The MWE will compile and run when executing javafx:run There will be an error related to the usage of automodules when executing javafx:jlink

I don't know how to fix this. ModiTect appears to be a promising addon. Another possible way can be found in this GitHub repo. But as I said before: My Maven knowledge is not sufficient to really grasp what is going on here. Any help would mean a lot to me!

MWE:

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.company</groupId>
    <artifactId>TestApp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>15</maven.compiler.source>
        <maven.compiler.target>15</maven.compiler.target>
    </properties>
    <dependencies>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>15.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>15.0.1</version>
        </dependency>

        <dependency>
            <groupId>de.jensd</groupId>
            <artifactId>fontawesomefx-fontawesome</artifactId>
            <version>4.7.0-9.1.2</version>
        </dependency>

        <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.34.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.12.0</version>
        </dependency>

        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>kernel</artifactId>
            <version>7.1.14</version>
        </dependency>

        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>layout</artifactId>
            <version>7.1.14</version>
        </dependency>

        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>io</artifactId>
            <version>7.1.14</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.7.30</version>
        </dependency>

    </dependencies>
    <build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>15</release>
                    <source>15</source>
                    <target>15</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.5</version>
                <configuration>
                    <mainClass>com.company.TestApp</mainClass>
                </configuration>
            </plugin>

        </plugins>
    </build>
</project>

module-info.java:

module com.company {
    requires javafx.controls;
    requires javafx.fxml;
    requires java.sql;
    requires org.apache.commons.lang3;
    requires kernel;
    requires layout;
    requires io;
    requires sqlite.jdbc;
    requires javafx.graphics;

    opens com.company to javafx.fxml;
    opens com.company.controllers to javafx.fxml;

    exports com.company;
    exports com.company.controllers;
}

TestAppController.java:

package com.company.controllers;


import javafx.event.ActionEvent;

import javafx.fxml.FXML;

import javafx.scene.control.Button;
import javafx.scene.control.TextArea;

import org.apache.commons.lang3.StringUtils;

import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;

import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.Document;

import java.io.FileNotFoundException;


public class TestAppController {

    @FXML
    private TextArea taText;

    @FXML
    private Button btnPrint;


    public void handleButtonAction(ActionEvent event) {
        if (event.getSource() == btnPrint) {
            setTaText();
            printPdf();
        }
    }

    public void setTaText() {
        taText.setText(StringUtils.leftPad("Random Text left padded by 50", 50));
    }

    public void printPdf() {
        String directoryString = "src/main/resources/com/company/pdf";

        try {
            String filepath = directoryString + "/" + "pdf_1" + ".pdf";
            PdfWriter writer = new PdfWriter(filepath);
            PdfDocument pdf = new PdfDocument(writer);
            Document document = new Document(pdf);
            document.add(new Paragraph(taText.getText()));
            document.close();
        } catch (FileNotFoundException e) {
            System.out.println(e.getMessage());
            return;
        }

    }
}

TestApp.java:

package com.company;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;


public class TestApp extends Application {

    public static void main(String[] args) {
        launch(args);
    }


    public void start(Stage primaryStage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("testApp.fxml"));
        Scene scene = new Scene(root);

        primaryStage.setScene(scene);
        primaryStage.setTitle("Test");

        primaryStage.show();
    }
}

testApp.fxml:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.text.Font?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.company.controllers.TestAppController">
   <top>
      <AnchorPane prefHeight="60.0" prefWidth="600.0" style="-fx-background-color: #337DFF;" BorderPane.alignment="CENTER" />
   </top>
   <center>
      <AnchorPane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
         <children>
            <Button fx:id="btnPrint" layoutX="240.0" layoutY="155.0" mnemonicParsing="false" onAction="#handleButtonAction" prefHeight="25.0" prefWidth="120.0" style="-fx-background-color: #337DFF;" text="Print PDF" textFill="WHITE">
               <font>
                  <Font name="System Bold" size="15.0" />
               </font>
            </Button>
            <TextArea fx:id="taText" layoutX="125.0" layoutY="44.0" prefHeight="82.0" prefWidth="350.0" />
         </children>
      </AnchorPane>
   </center>
</BorderPane>

解决方案

Instead of the javafx maven plugin you could use the moditect plugin to create missing module-info to auto module dependencies and then build the image with moditect.

Such a pom for you could be something like:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.company</groupId>
<artifactId>TestApp</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <appName>TestApp</appName>
    <launcherName>testapp</launcherName>
    <moduleName>com.company</moduleName>
    <mainClass>com.company.LoginApp</mainClass>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>15</maven.compiler.source>
    <maven.compiler.target>15</maven.compiler.target>
    <version.java>15</version.java>
</properties>

<dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>15.0.1</version>
    </dependency>

    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>15.0.1</version>
    </dependency>

    <dependency>
        <groupId>de.jensd</groupId>
        <artifactId>fontawesomefx-fontawesome</artifactId>
        <version>4.7.0-9.1.2</version>
    </dependency>

    <dependency>
        <groupId>org.xerial</groupId>
        <artifactId>sqlite-jdbc</artifactId>
        <version>3.34.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.12.0</version>
    </dependency>

    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>kernel</artifactId>
        <version>7.1.14</version>
    </dependency>

    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>layout</artifactId>
        <version>7.1.14</version>
    </dependency>

    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>io</artifactId>
        <version>7.1.14</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.30</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <release>${version.java}</release>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.1.2</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/modules</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.moditect</groupId>
            <artifactId>moditect-maven-plugin</artifactId>
            <version>1.0.0.RC1</version>
            <executions>
                <execution>
                    <id>add-module-info-to-dependencies</id>
                    <phase>package</phase>
                    <configuration>
                        <outputDirectory>${project.build.directory}/modules</outputDirectory>
                        <overwriteExistingFiles>true</overwriteExistingFiles>
                        <modules>
                            <module>
                                <artifact>
                                    <groupId>com.itextpdf</groupId>
                                    <artifactId>kernel</artifactId>
                                </artifact>
                                <moduleInfo>
                                    <name>kernel</name>
                                </moduleInfo>
                            </module>
                            <module>
                                <artifact>
                                    <groupId>com.itextpdf</groupId>
                                    <artifactId>layout</artifactId>
                                </artifact>
                                <moduleInfo>
                                    <name>layout</name>
                                </moduleInfo>
                            </module>
                            <module>
                                <artifact>
                                    <groupId>com.itextpdf</groupId>
                                    <artifactId>io</artifactId>
                                </artifact>
                                <moduleInfo>
                                    <name>io</name>
                                </moduleInfo>
                            </module>
                            <module>
                                <artifact>
                                    <groupId>org.xerial</groupId>
                                    <artifactId>sqlite-jdbc</artifactId>
                                </artifact>
                                <moduleInfo>
                                    <name>sqlite.jdbc</name>
                                </moduleInfo>
                            </module>
                            <module>
                                <artifact>
                                    <groupId>org.apache.commons</groupId>
                                    <artifactId>commons-lang3</artifactId>
                                </artifact>
                                <moduleInfo>
                                    <name>org.apache.commons.lang3</name>
                                </moduleInfo>
                            </module>
                            <module>
                                <artifact>
                                    <groupId>org.slf4j</groupId>
                                    <artifactId>slf4j-api</artifactId>
                                </artifact>
                                <moduleInfo>
                                    <name>org.slf4j</name>
                                </moduleInfo>
                            </module>
                        </modules>
                        <module>
                            <mainClass>${mainClass}</mainClass>
                            <moduleInfoFile>${project.build.sourceDirectory}/module-info.java</moduleInfoFile>
                        </module>
                        <jdepsExtraArgs>
                            <args>--multi-release</args> <args>15</args>
                            <args>--ignore-missing-deps</args>
                        </jdepsExtraArgs>
                    </configuration>
                    <goals>
                        <goal>add-module-info</goal>
                    </goals>
                </execution>
                <execution>
                    <id>create-runtime-image</id>
                    <phase>package</phase>
                    <goals>
                        <goal>create-runtime-image</goal>
                    </goals>
                    <configuration>
                        <modulePath>
                            <path>${project.build.directory}/modules</path>
                        </modulePath>
                        <modules>
                            <module>${moduleName}</module>
                        </modules>
                        <launcher>
                            <name>${launcherName}</name>
                            <module>${moduleName}</module>
                        </launcher>
                        <compression>2</compression>
                        <stripDebug>true</stripDebug>
                        <outputDirectory>${project.build.directory}/jlink-image</outputDirectory>
                        <ignoreSigningInformation>true</ignoreSigningInformation>
                    </configuration>
                </execution>

            </executions>
        </plugin>
        <plugin>
            <groupId>com.github.akman</groupId>
            <artifactId>jpackage-maven-plugin</artifactId>
            <version>0.1.2</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>jpackage</goal>
                    </goals>
                    <configuration>
                        <name>${appName}</name>
                        <type>IMAGE</type>
                        <runtimeimage>${project.build.directory}/jlink-image</runtimeimage>
                        <module>${moduleName}/${mainClass}</module>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

</project>

My first tests seems to be successful but a few items might need more work (e.g. I do not like to have the --ignore-missing-deps argument)

Maybe this helps a little to get you forward.

这篇关于分发使用自动模块的JavaFX应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆