问题
We had a guy working with us who used the maven-assembly-plugin to package all dependencies. He has since left the company and I'm trying to figure out how he did this. I am just now learning about the maven-assembly-plugin.
Our applications are split into a Maven POM project with associated module projects. In the following example, I've included the runtime module project. I tried to create a module project called runtime in my application, but the minute I make any changes it loses the association with the parent project.
We are using Netbeans.
+- pom.xml
+- Simulator
+- pom.xml
+- comms
+- pom.xml
+- src
+- main
+- java
+- framework
+- pom.xml
+- src
+- main
+- java
+- core
+- pom.xml
+- src
+- main
+- java
This is what I want to create:
+- runtime
+- pom.xml
+- src
+- assemble
+- assembly (xml file)
+- target
+- Simulator
+- archive-tmp
+- classes
+- test-classes
+- Simulator (zip file)
+- config
+- data
+- scripts
After doing a little more research, I think I might be putting the cart before the horse. I already have a main project that includes the module projects.
- So what exactly is the first next step?
- Create the assembly descriptor file?
- Edit my main pom file to be the parent?
Below are some helpful questions and answers but I'm still confused. Can someone please tell me what to do first?
Maven assembly on multi module project with special structure
How to use Maven assembly plugin with multi module maven project
EDIT:
I figured out why the module was disappearing from my main project. Netbeans!! I restarted it and my runtime module was there.
So, now I need to edit my POM file in the runtime module?
回答1:
If I read your question right, what you want to do is to add a new Maven module (called runtime
) to an existing project and use the maven-assembly-plugin
on this new project to package it.
The first step is then to create the Maven module. I'm not sure if Netbeans provides a facility to do this (Eclise does), but it comes down to:
- in the
<modules>
section of the parent POM, add a new<module>
forruntime
. - create a new folder called
runtime
at the same directory level of the parent POM create a file
pom.xml
inside this new folder declaring the root POM as parent POM like this:<parent> <groupId>...</groupId> <artifactId>...</artifactId> <version>...</version> </parent>
Then, you need to configure the maven-assembly-plugin to do the packaging of this new module. This is done with the help of a assembly descriptor, whose format is documented here.
To give you something to start with, consider the following POM configuration and assembly descriptor, that will package everything that is under config
, data
and scripts
in a zip file:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/assemble/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
with the assembly.xml
:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>distribution</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>config</directory>
<outputDirectory>/config</outputDirectory>
</fileSet>
<fileSet>
<directory>data</directory>
<outputDirectory>/data</outputDirectory>
</fileSet>
<fileSet>
<directory>scripts</directory>
<outputDirectory>/scripts</outputDirectory>
</fileSet>
</fileSets>
</assembly>
After running mvn clean install
on the parent POM, a zip file will be created under the target
directory of the module runtime
. It will contain the 3 specified folders.
来源:https://stackoverflow.com/questions/33088454/getting-started-with-maven-assembly-plugin-with-multi-module-project