【JavaFX 高版本模块化,打包exe】

JavaFX 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.zb</groupId>
  <artifactId>JFXdemo</artifactId>
  <version>1.0.0</version>
  <name>JFXdemo</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <junit.version>5.8.1</junit.version>
  </properties>

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

<!--    <dependency>-->
<!--      <groupId>org.junit.jupiter</groupId>-->
<!--      <artifactId>junit-jupiter-api</artifactId>-->
<!--      <version>${junit.version}</version>-->
<!--      <scope>test</scope>-->
<!--    </dependency>-->
<!--    <dependency>-->
<!--      <groupId>org.junit.jupiter</groupId>-->
<!--      <artifactId>junit-jupiter-engine</artifactId>-->
<!--      <version>${junit.version}</version>-->
<!--      <scope>test</scope>-->
<!--    </dependency>-->
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>17</source>
          <target>17</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-maven-plugin</artifactId>
        <version>0.0.8</version>
        <executions>
          <execution>
            <!-- Default configuration for running with: mvn clean javafx:run -->
            <id>default-cli</id>
            <configuration>
              <mainClass>com.zb.jfxdemo/com.zb.jfxdemo.HelloApplication</mainClass>
              <launcher>app</launcher>
              <jlinkZipName>app</jlinkZipName>
              <jlinkImageName>app</jlinkImageName>
              <noManPages>true</noManPages>
              <stripDebug>true</stripDebug>
              <noHeaderFiles>true</noHeaderFiles>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- 第二种方式打包:生成主程序JAR包和依赖lib文件夹 -->
      <!-- 设置程序主类和依赖文件夹 -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
          <archive>
            <addMavenDescriptor>false</addMavenDescriptor>
            <manifest>
              <addClasspath>true</addClasspath>
              <classpathPrefix>lib/</classpathPrefix>
              <mainClass>com.zb.jfxdemo.HelloApplication</mainClass>
            </manifest>
<!--            <manifestEntries>-->
<!--              <Class-Path>./</Class-Path>-->
<!--            </manifestEntries>-->
          </archive>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <type>jar</type>
              <includeTypes>jar</includeTypes>
              <outputDirectory>${project.build.directory}/lib</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

打包exe.bat

::打包成exe
jpackage --type app-image -n HelloJFX -p . -m com.zb.jfxdemo/com.zb.jfxdemo.HelloApplication --vendor bo --app-version 1.0.0 --icon .\logo.ico

::模块化运行
::java --module-path ./lib --add-modules=javafx.controls,javafx.fxml,javafx.base -jar JFXdemo-1.0.0.jar

pause

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值