Maven Assembly Build Release Package

original
2016/06/01 14:54
Reading number 732

Maven's appearance has further deepened everyone's enthusiasm for modular development. How to better package can make our work more efficient. The Assembly plug-in provided by Maven can help you build a complete release package. Next, we will release a zip package based on an instance.

The name of the gserver project, including the following modules:

 Services: Gserver gate: gateway server Gserver logic: logical server Public class: Gserver core: core class Gserver edits: Redis cache management Gserver services: logical class Gserver db: MySQL database management pack: Gserver distribute: packager, path/target directory

The whole project includes two processes and four modules, and four common modules are used by two processes respectively;

The whole idea of packaging is: Each module is packaged separately first, and then summarized through another module

We need to provide a specially packaged module, that is gserver-distribute The module itself is an empty module, which only provides The xml file required by the Assembly plug-in may also provide some public configuration files.

Since gserver distribute is a summary module, ensure that gserver distribute is the last execution module, as shown below:

 <modules> <module>gserver-core</module> <module>gserver-redis</module> <module>gserver-services</module> <module>gserver-gate</module> <module>gserver-logic</module> <module>gserver-db</module> <module>gserver-distribution</module> </modules>

Gserver distribute appears at the bottom of all modules; Let's take a look at how gserver distribute is packaged using the Assembly plug-in.

You need to provide a packaged configuration file for the Assembly plug-in: assembly.xml, and then pom.xml for configuration

The plug-ins used for pom.xml configuration are as follows:

 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.4</version> <configuration> <descriptors> <descriptor>assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build>

Now let's take a look at the assembly.xml configuration file:

 <assembly> <id>bin</id> <!--  Finally packaged into a zip file for publishing --> <formats> <format>zip</format> </formats> <!--  Adds dependencies to zip package under lib directory --> <dependencySets> <dependencySet> <!--  Do not use the artifact of the project. Do not decompress third-party jars. Package them into the lib directory of the zip file --> <useProjectArtifact>false</useProjectArtifact> <outputDirectory>lib</outputDirectory> <unpack>false</unpack> <!--  Exclude the specified module --> <excludes>   <exclude>com.gserver:gserver-logic</exclude>   <exclude>com.gserver:gserver-gate</exclude>   </excludes>   </dependencySet> </dependencySets> <fileSets> <!--  Package the startup script file in the project's script file directory (src/main/scripts) into the following directory of the zip file --> <fileSet> <directory>../ gserver-logic/shell</directory> <outputDirectory></outputDirectory> <includes> <include>*</include> </includes> </fileSet> <fileSet> <directory>../ gserver-gate/shell</directory> <outputDirectory></outputDirectory> <includes> <include>*</include> </includes> </fileSet> <fileSet> <directory>../ gserver-distribution/shell</directory> <outputDirectory></outputDirectory> <includes> <include>*</include> </includes> </fileSet> <fileSet> <directory>../ gserver-logic/target</directory> <outputDirectory></outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> <fileSet> <directory>../ gserver-gate/target</directory> <outputDirectory></outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> <fileSet> <directory>../ gserver-logic/logic-config</directory> <outputDirectory>logic-config</outputDirectory> <includes> <include>*</include> </includes> </fileSet> <fileSet> <directory>../ gserver-gate/gate-config</directory> <outputDirectory>gate-config</outputDirectory> <includes> <include>*</include> </includes> </fileSet> </fileSets> </assembly>

These are the main settings, which are more detailed: https://github.com/ksfzhaohui/gserver

The whole package will finally be packaged into a zip package. Of course, it also supports many other formats. For more details, see the Maven Assembly plug-in. Here is a brief introduction to the whole process.

Last zip package: gserver-distribution-0.0.1-SNAPSHOT-bin.zip, The interior is as shown in the figure below:

Well, at this time, you can directly throw it to the client, test, plan, and let them start the service with one click( all-startup.bat ), one button stop service( all-shutdown.bat )

Expand to read the full text
Loading
Click to lead the topic 📣 Post and join the discussion 🔥
Reward
zero comment
four Collection
zero fabulous
 Back to top
Top