[Instructions]
-
This article is only about POM code for plugin s in Maven.
-
For Maven's common dependency configuration codes, see my other blog:
Common Dependency Configuration Codes for Maven Profile POM:
https://blog.csdn.net/wangpaiblog/article/details/112797500
ordinary
Running Environment
JDK 17
Maven 3.6.3
IntelliJ IDEA 2020.2.2 (Ultimate Edition)
POM Code
Put Maven multi-module dependent integration into a JAR package
_This plug-in can be used in the JAR package of the cost module in Maven's current module, which contains all the JAR packages that this module directly or indirectly depends on, as well as all the resource files that they directly or indirectly depend on. If you do not use this plug-in in the parent POM, you need to manually install the other modules that this module depends on into the Maven repository in advance, so it is recommended that you install them in the parent POMThis plug-in is used in POM.
The command to use this plug-in is: mvn package assembly:single.
<project xmlns=...> <build> <plugins> <!-- This plugin must be placed on the parent POM in --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.3.0</version> <executions> <!-- This plug-in can be executed by executing the following commands in the home directory: mvn package assembly:single about IntelliJ IDEAļ¼Generated JAR Folders where packages are located under each module target --> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <!-- here IntelliJ IDEA May turn red, this is normal --> <goal>single</goal> </goals> </execution> </executions> <configuration> <archive> <manifest> <!-- The class where the configurator runs the entry --> <mainClass>Package Name.Class name</mainClass> </manifest> </archive> <!-- Set up JAR Package Output Directory --> <outputDirectory>${project.build.directory}/#maven-assembly-plugin</outputDirectory> <!-- Set up packaged JAR Package directory structure is default --> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> </build> </project>
Generate Single Entry Class JAR Package
_This plug-in can be used to generate single-entry class JAR packages in the current module of Maven. The JAR packages generated by this plug-in contain only the files of the current module (including the resource files under this module)., although it does not contain any dependencies, it sets the relative path of the program runtime entry class, which relies on JAR packages. Dependent JAR packages can be placed in the specified directory, then only through this JAR package (there is no need to specify the dependent package path in the command line)To run Java applications. Therefore, this plug-in is generally used in the program entry module. This plug-in is often used in conjunction with the plug-in maven-dependency-plugin.
<project xmlns=...> <build> <plugins> <!-- This plugin can be used to generate single-entry classes in the current module JAR Package. This plugin is often associated with a plugin maven-dependency-plugin Use together --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.2.0</version> <configuration> <archive> <manifest> <!-- The class where the configurator runs the entry --> <mainClass>Package Name.Class name</mainClass> <!-- Setup program ClassPath Route. This means in the command line java -cp XXX in -cp The content of the parameter. In other words, this item is dependent JAR Package directory. If this item is set and then dependent JAR Put all packages in the directory lib/ Next, Then you can use it directly java -jar XXX.jar To run this JAR Package without specifying dependencies in commands --> <classpathPrefix>lib/</classpathPrefix> <addClasspath>true</addClasspath> </manifest> </archive> <!-- Set up JAR Package Output Directory --> <outputDirectory>${project.build.directory}/#maven-jar-plugin</outputDirectory> </configuration> </plugin> </plugins> </build> </project>
Generate a fully dependent single JAR package
_This plug-in can be used to generate complete dependent single JAR packages in Maven's current module. Complete means that JAR packages that are directly or indirectly dependent on this module will be generated, and that each of these JAR packages contains the resource files of the module to which they belong. Single JAR packages refer to the generation of dependent packages that do not intersect (have no duplicate dependencies) with each other.This plug-in is often used in conjunction with the plug-in maven-jar-plugin.
<project xmlns=...> <build> <plugins> <!-- This plug-in is used to generate all the dependencies referenced directly and indirectly by the module. But the generated does not include its own JAR Package, so there is no need to set the program run entry class in the settings of this plug-in. This plug-in can be used in the life cycle package Is executed. This plugin is often associated with a plugin maven-jar-plugin Use together --> <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> <!-- Set up JAR Package Output Directory --> <outputDirectory>${project.build.directory}/#maven-jar-plugin/lib</outputDirectory> <overWriteReleases>true</overWriteReleases> <overWriteSnapshots>true</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> <includeScope>compile</includeScope> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
Export Resource File
_This plug-in can be used to export the resource files needed for this module in Maven's current module. However, the generated resource files only contain the resource files for this module, not for other modules on which it depends. This plug-in is often used with the plug-ins maven-jar-plugin, maven-dependency-plugin. This plug-in is recommended for use in parent POM.
<project xmlns=...> <build> <plugins> <!-- This plug-in is a resource file used to copy the module, which refers to the specified directory. However, the resourcesfile generated only contains the resourcesfile of this module, not the resourcesfile of other modules on which it depends This plug-in can be used in the life cycle package Is executed. This plugin is often associated with a plugin maven-jar-plugin,maven-dependency-plugin Use together This plugin is recommended to be placed on the parent POM in --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <id>copy-resources</id> <!-- Set the execution stage of this plug-in to change to another stage --> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <!-- Set Resource File Output Directory --> <outputDirectory>${project.build.directory}/#maven-resources-plugin</outputDirectory> <resources> <resource> <!-- Set the directory where the original resource file is located --> <directory>src/main/resources</directory> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
JavaFX
Running Environment
JDK 17
JavaFX 17-ea+11
Maven 3.6.3
IntelliJ IDEA 2020.2.2 (Ultimate Edition)
POM Code
Add the ability to run JavaFX applications from the command line using the Maven command
<project xmlns=...> <build> <plugins> <!-- In this directory, use commands mvn javafx:run To run this plug-in --> <plugin> <groupId>org.openjfx</groupId> <artifactId>javafx-maven-plugin</artifactId> <version>0.0.6</version> <executions> <execution> <id>default-cli</id> <configuration> <mainClass>Package Name.Class name</mainClass> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>