Get the App
SLTechnology News&Howtos  ›  Development  › 

The implementation method of JDK11+ Modular Project Packaging

Shulou Source: shulou.com Published: 2022-06-03 05:16:11 10月01日 Update

This article mainly introduces "the implementation method of JDK11+ modular project packaging". In the daily operation, I believe that many people have doubts about the implementation method of JDK11+ modular project packaging. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "JDK11+ modular project packaging". Next, please follow the editor to study!

JavaFx packaged development environment

Windows10

STS: 4.7.2.RELEASE (eclipse2.3.200.v20200604-0540)

OpenJDK11.0.9

MAVEN3.6.3

Preparation work to create maven project com.studyjfx-demo0.0.1-SNAPSHOT

Compilation configuration

Org.apache.maven.plugins maven-compiler-plugin 3.6.2 11 11 UTF-8

The project directory structure is as follows:

Coding

Launch class 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);}}

Modular file

Module com.study.jfx {requires javafx.controls; opens com.study.jfx to javafx.controls; exports com.study.jfx;}

Description of the modular configuration:

Declare the name of the modular project.

Declare dependent modules without repeating javafx.base and javafx.graphics.

Open the classes of this project to javafx.controls.

Export this project class, start the project needs.

Dependent library configuration of maven

Org.openjfx javafx-controls 11.0.2

Maven plug-in configuration 1:

Org.apache.maven.plugins maven-dependency-plugin 3.1.2 copy-dependencies package ${basedir} / target/lib false False true copy-dependencies org.apache.maven.plugins Maven-assembly-plugin 3.3.0 false jar-with-dependencies com.study.jfx.App Make-assembly package single JavaFx calls executable jar package

Using plug-in configuration 1, execute the maven command: clean package, and the following directory will be generated under the target folder:

The cmd command starts the project:

Java-module-path lib-add-modules=javafx.controls,javafx.base,javafx.graphics-jar jfx-demo-0.0.1-SNAPSHOT.jarJRE customization

Maven plug-in configuration II:

Org.openjfx javafx-maven-plugin 0.0.5 com.study.jfx.App

Using the creation provided by JavaFx, execute the maven command clean javafx:jlink to customize the JRE. Of course, it is better to customize using the jdeps+jlink provided by JDK itself.

Description

This configuration starts the project directly by executing the main method, without relying on the javafx-maven-plugin command clean javafx:run.

Packaging with this configuration is also successful with OpenJDK15 first.

I don't know why I use a second JavaFx environment (a separate workspace) in an IDE and there is an exception that the JVM dependent libraries do not match.

The plug-in version can also be successfully packaged and run.

At this point, the study on "the implementation method of JDK11+ modular project packaging" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Project module configuration method command plug-in learning success file more environment directory work help utility next no name folder article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Huawei vpn Shulou Information Apple