问题描述
我们有一个与我们合作的人使用maven-assembly-plugin打包所有依赖项。他已离开公司,我正试图弄清楚他是如何做到这一点的。我刚刚学习maven-assembly-plugin。
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.
我们的应用程序被拆分为Maven POM项目以及相关的模块项目。在下面的示例中,我已经包含了运行时模块项目。我尝试在我的应用程序中创建一个名为runtime的模块项目,但是当我做出任何更改时,它会失去与父项目的关联。
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.
我们正在使用Netbeans。
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.
- 那么下一步到底是什么?
- 创建程序集描述符文件?
- 将我的主pom文件编辑为父级?
以下是一些有用的问题和答案,但我仍然感到困惑。有人可以告诉我先做什么吗?
Below are some helpful questions and answers but I'm still confused. Can someone please tell me what to do first?
编辑:
我想通了为什么模块从我的主项目中消失了。 Netbeans !! 我重启了它,我的运行时模块就在那里。
I figured out why the module was disappearing from my main project. Netbeans!! I restarted it and my runtime module was there.
那么,现在我需要在运行时模块中编辑我的POM文件?
So, now I need to edit my POM file in the runtime module?
推荐答案
如果我正确地读了你的问题,你想要做的是添加一个新的Maven模块(称为 runtime
)到现有项目并在这个新项目中使用 maven-assembly-plugin
打包它。
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.
然后第一步是创建Maven模块。我不确定Netbeans是否提供了这样做的设施(Eclise确实如此),但它归结为:
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
< modules>
父POM的部分,为runtime < module>
/ code>。 - 在父POM的同一目录级别创建一个名为
runtime
的新文件夹 -
在这个新文件夹中创建一个文件
pom.xml
,将根POM声明为父POM,如下所示:
- 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>
然后,你需要配置做这个新模块的包装。这是在程序集描述符的帮助下完成的,其格式为。
为了给你一些开始,请考虑以下POM配置和汇编描述符,它将打包 config下的所有内容zip文件中的
,数据
和脚本
:
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>
使用 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>
在父母上运行 mvn clean install
之后POM,将在模块 runtime
的目标
目录下创建一个zip文件。它将包含3个指定的文件夹。
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.
这篇关于使用多模块项目开始使用Maven程序集插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!