gpt4 book ai didi

maven-2 - 如何创建不将依赖项解压到自己的文件夹中的 Maven 程序集?

转载 作者:行者123 更新时间:2023-12-02 15:12:53 24 4
gpt4 key购买 nike

我想构建一个独立的存档,其中包含一个 OSGi 容器,供我的项目 bundle 在其中运行。目标是拥有一个可以立即下载、解压和启动的存档。

我正在使用 Maven 程序集插件来创建存档。通过下面的程序集描述符和对 Apache Karaf 的单一依赖,我在存档中获得以下结构:

+-apache-karaf-2.2.1  |  +-bin  +-demos  ... etc ..

I want to strip the base directory of the unpacked dependency, have my own base directory at the top and exclude some of the folders (e. g. demos) and then add my own bundles and config files. It looks like I can't do all of that with the assembly plugin, is there another plugin I can use?

Here's my assembly descriptor:

<assembly>
<id>dist-full</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveDependencies>false</useTransitiveDependencies>
</dependencySet>
</dependencySets>
</assembly>

请注意,includeBaseDirectory 仅设置为 false,因为我希望至少具有正确的级别数,然后我只需在解压后重命名该内容即可。最好保留基本目录并删除依赖项的 basedir。

最佳答案

使用maven-dependency-plugin解压依赖项,然后在程序集描述符中使用fileSets。就像这样:

pom.xml:

<project>
<!-- ... -->

<dependencies>
<dependency>
<groupId>org.apache.karaf</groupId>
<artifactId>apache-karaf</artifactId>
<version>2.2.1</version>
<type>tar.gz</type>
</dependency>
</dependencies>

<!-- ... -->

<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>prepare-runtime</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeTransitive>true</excludeTransitive>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>distribution-package</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptor>assembly.xml</descriptor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<!-- ... -->
</project>

程序集.xml:

<assembly>
<id>dist-full</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>${groupId}.${artifactId}-${version}</baseDirectory>
<fileSets>
<fileSet>
<directory>target/dependency/apache-karaf-2.2.1</directory>
<outputDirectory />
<includes>
<include>bin/**</include>
<include>lib/**</include>
<include>etc/**</include>
<include>deploy/**</include>
<include>system/**</include>
</includes>
</fileSet>
</fileSets>
</assembly>

关于maven-2 - 如何创建不将依赖项解压到自己的文件夹中的 Maven 程序集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6509957/

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