這篇文章主要介紹“JDK11+模塊化項目打包的實現(xiàn)方法”,在日常操作中,相信很多人在JDK11+模塊化項目打包的實現(xiàn)方法問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”JDK11+模塊化項目打包的實現(xiàn)方法”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
成都創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站設計、成都網(wǎng)站建設與策劃設計,淅川網(wǎng)站建設哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設十載,網(wǎng)設計領域的專業(yè)建站公司;建站業(yè)務涵蓋:淅川等地區(qū)。淅川做網(wǎng)站價格咨詢:028-86922220
windows10
STS: 4.7.2.RELEASE(eclipse2.3.200.v20200604-0540)
OpenJDK11.0.9
MAVEN3.6.3
<groupId>com.study</groupId> <artifactId>jfx-demo</artifactId> <version>0.0.1-SNAPSHOT</version>
編譯配置
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.2</version> <configuration> <source>11</source> <target>11</target> <encoding>UTF-8</encoding> </configuration> </plugin>
項目目錄結構如下:
啟動類App.java
package com.study.jfx; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class App extends Application { public static void main(String[] args) { launch(args); } @Override public void start(@SuppressWarnings("exports") Stage primaryStage) throws Exception { primaryStage.setTitle("wxCert"); primaryStage.show(); Button btn = new Button(); btn.setText("Say 'Hello World'"); btn.setOnAction(event -> { System.out.println("Hello World!"); }); StackPane root = new StackPane(); root.getChildren().add(btn); Scene scene = new Scene(root, 300, 250); primaryStage.setScene(scene); } }
模塊化文件
module com.study.jfx { requires javafx.controls; opens com.study.jfx to javafx.controls; exports com.study.jfx; }
模塊化配置的說明:
聲明模塊化項目的名稱。
聲明依賴的模塊,不用重復聲明javafx.base和javafx.graphics。
給javafx.controls開放本項目的類。
導出本項目類,啟動項目需要。
maven的依賴庫配置
<dependencies> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-controls</artifactId> <version>11.0.2</version> </dependency> </dependencies>
maven插件配置一:
<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> <configuration> <outputDirectory>${basedir}/target/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> <goals> <goal>copy-dependencies</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.3.0</version> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.study.jfx.App</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
使用插件配置一,執(zhí)行maven命令:clean package
,會在target文件夾下生成如下目錄:
cmd命令啟動項目:
java --module-path lib --add-modules=javafx.controls,javafx.base,javafx.graphics -jar jfx-demo-0.0.1-SNAPSHOT.jar
maven插件配置二:
<plugin> <groupId>org.openjfx</groupId> <artifactId>javafx-maven-plugin</artifactId> <version>0.0.5</version> <configuration> <mainClass>com.study.jfx.App</mainClass> </configuration> </plugin>
使用JavaFx提供的創(chuàng)建,執(zhí)行maven命令clean javafx:jlink
可以定制JRE。 當然,使用JDK自身提供的jdeps+jlink來定制更好。
這一配置可以直接通過執(zhí)行main方法啟動項目,不需要依賴javafx-maven-plugin的命令clean javafx:run
來啟動項目。
先用OpenJDK15使用此配置打包也成功了。
不知道為什么我在一個IDE里面使用第二個JavaFx環(huán)境(單獨的工作空間)會出JVM依賴庫不匹配的異常。
插件版本降低也能成功打包運行。
到此,關于“JDK11+模塊化項目打包的實現(xiàn)方法”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
當前題目:JDK11+模塊化項目打包的實現(xiàn)方法
標題網(wǎng)址:http://jinyejixie.com/article10/jdoogo.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供響應式網(wǎng)站、搜索引擎優(yōu)化、用戶體驗、網(wǎng)站設計公司、域名注冊、網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)