Maven 2 自定义maven程序集
我开始与Maven合作,但还没有成功地用Maven的方式思考。我有一个特定的要求,文档没有给我足够的线索,所以我需要一些帮助: 我想创建一个Maven 2 自定义maven程序集,maven-2,maven-assembly-plugin,Maven 2,Maven Assembly Plugin,我开始与Maven合作,但还没有成功地用Maven的方式思考。我有一个特定的要求,文档没有给我足够的线索,所以我需要一些帮助: 我想创建一个 构建一个带有依赖项的jar,类似于此名称的“标准”目标,但不包括一些资源。我希望log4j.properties和一些其他配置文件不在jar中 构建一个.ZIP文件,在其根目录中包含步骤1中的.jar,以及上述配置文件 我想从命令行(仅)启动这个程序集,因此不需要绑定到某个阶段(或目标?mojo?)。最好使用assembly:assembly或assemb
jar,类似于此名称的“标准”目标,但不包括一些资源。我希望log4j.properties
和一些其他配置文件不在jar中
.ZIP
文件,在其根目录中包含步骤1中的.jar
,以及上述配置文件assembly:assembly
或assembly:single
- 我需要为此自定义程序集描述符吗李>
- 我真的不能将它嵌套在
中吗?因此它进入pom.xml
,并被src/assembly/something.xml
引用描述符ref
- 我可以将其编码为两个相对简单的程序集,其中一个构建在另一个程序集上(即.Zip程序集使用.Jar程序集),还是必须在一个程序集中完成所有工作
src/main/assembly
。不,descriptor如果
用于内置描述符,则必须在此处使用descriptor
我可以将其编码为两个相对简单的程序集,其中一个构建在另一个程序集上(即.Zip程序集使用.Jar程序集),还是必须在一个程序集中完成所有工作
正如所暗示的,您将需要两个程序集描述符。让我帮点忙
假设您有以下项目结构:
$ tree .
.
├── pom.xml
└── src
├── main
│ ├── assembly
│ │ ├── jar.xml
│ │ └── zip.xml
│ ├── java
│ │ └── com
│ │ └── stackoverflow
│ │ └── App.java
│ └── resources
│ └── log4j.properties
└── test
└── java
└── com
└── stackoverflow
└── AppTest.java
“过滤”uberjar(jar.xml)的描述符如下所示:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>uberjar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<scope>runtime</scope>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
<excludes>
<exclude>log4j.properties</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/resources</directory>
<outputDirectory/>
<includes>
<include>log4j.properties</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory/>
<includes>
<include>*-uberjar.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
向帕斯卡致敬,非常感谢你给出了这个非常有用的答案!我希望你能回复,我甚至考虑过直接联系你。“在船上”可能有点言过其实:自从我开始尝试在Maven中运行它以来,各种各样的灾难,似乎是随机的,一直困扰着我的构建。我仍然觉得Maven有一张只有母亲才会喜欢的脸。但相信你的判断,我会继续努力,希望在我失去耐心之前,在学习过程中达到一个平稳期;)@Carl我想知道是否有人强迫你使用Maven,也许是把你的家人扣为人质:)更严重的是,祝贺你的倡议,如果我能让你的经历更好一点,我会很乐意帮助你。关于“人质”的猜测大致正确——这是一个工作项目。工作起来很有魅力,顺便说一句。再次感谢。有什么方法可以影响
.zip
上的-bin
后缀吗?@Carl bwuhaah:)关于后缀,它来自程序集
。愚蠢的我,那是我忘了看的地方。谢谢
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/resources</directory>
<outputDirectory/>
<includes>
<include>log4j.properties</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory/>
<includes>
<include>*-uberjar.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>uberjar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<scope>runtime</scope>
<unpackOptions>
<excludes>
<exclude>META-INF/maven/**</exclude>
</excludes>
</unpackOptions>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
<excludes>
<exclude>log4j.properties</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>