gpt4 book ai didi

java - 使用 Maven 程序集插件组合 Jar-with-dependencies 和 ZIP 文件

转载 作者:太空狗 更新时间:2023-10-29 22:41:31 25 4
gpt4 key购买 nike

我想将我的源代码与所有依赖项合并到一个 JAR 中,并将其与其他文件一起打包到一个 zip 文件中。我能够创建一个包含所有依赖项以及 ZIP 文件的 Jar,但我无法将两者结合起来。

我最终希望 zip 文件中有以下目录结构:

loader/bin/shellscript.sh

loader/lib/jar-with-dependencies.jar

loader/appname/config/config.xml

这是我的 pom 文件的摘录:

<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>

这是我的程序集的摘录

<assembly>
<id>bin</id>
<!-- Specifies that our binary distribution is a zip package -->
<formats>
<format>zip</format>
</formats>

<baseDirectory>SpreadsheetLoaderApp</baseDirectory>

<fileSets>
<fileSet>
<directory>corporatebondpurchases</directory>
<outputDirectory>${basedir}/corporatebondpurchases/config</outputDirectory>
<includes>
<include>*.xml</include>
<include>*.properties</include>
</includes>
</fileSet>
<fileSet>
<directory>corporatebondpurchases</directory>
<outputDirectory>${basedir}/bin</outputDirectory>
<includes>
<include>*.sh</include>
</includes>
</fileSet>
</fileSets>
</assembly>

这是部分构建的输出:

[INFO] --- maven-assembly-plugin:2.4:single (default-cli) @ SpreadsheetLoader ---
[INFO] Reading assembly descriptor: src/main/assembly/assembly.xml
[INFO] Building zip: C:\Software\SpringSTS\workspace\SpreadsheetLoader\target\SpreadsheetLoader-0.0.1-SNAPSHOT-bin.zip
[INFO] Building jar: C:\Software\SpringSTS\workspace\SpreadsheetLoader\target\SpreadsheetLoader-0.0.1-SNAPSHOT-jar-with-dependencies

这成功地在目标下创建了一个 Jar 以及 ZIP 文件(尽管使用完整路径而不是相对路径)。我想要的是将 Jar 文件作为 zip 文件的一部分包含在内。

编辑:

在研究了各种博客文章之后,我设法通过使用以下 POM 和程序集文件来实现这一点

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
</configuration>
</execution>
<execution>
<id>dist</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

以及对应的汇编文件...

<assembly>
<id>dist</id>
<!-- Specifies that our binary distribution is a zip package -->
<formats>
<format>zip</format>
</formats>

<includeBaseDirectory>true</includeBaseDirectory>
<baseDirectory>SpreadsheetLoader</baseDirectory>

<files>
<file>
<source>target/${project.artifactId}-${project.version}-jar-with-dependencies.jar</source>
<outputDirectory>lib</outputDirectory>
</file>
</files>

<fileSets>
<fileSet>
<directory>applicationbuild/${buildname}</directory>
<outputDirectory>${buildname}/config</outputDirectory>
<includes>
<include>*.xml</include>
<include>*.properties</include>
</includes>
</fileSet>
<fileSet>
<directory>applicationbuild/${buildname}</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>*.sh</include>
</includes>
<lineEnding>unix</lineEnding>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>./</directory>
<outputDirectory>logs</outputDirectory>
<excludes>
<exclude>*/**</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>./</directory>
<outputDirectory>${buildname}/sourcedata</outputDirectory>
<excludes>
<exclude>*/**</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>

这为我提供了一个用于部署目的的简单目录结构。我的主要信息来源来自以下站点:

http://www.drawbackz.com/stack/175442/maven-assembly-plugin-how-to-create-nested-assemblies.html

谢谢

最佳答案

我对上面的结果很满意。然而,这是我第一次尝试使用 Maven。如果有人有更好的方法来做到这一点,我很乐意接受建议。

关于java - 使用 Maven 程序集插件组合 Jar-with-dependencies 和 ZIP 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28932729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com