标签: maven-assembly-plugin

java maven重建依赖

我有一个项目有依赖A.项目正在打包到WAR和依赖A - 进入jar.另一个依赖关系B,也依赖于A.我想打包项目,当项目B打包时,它必须重建其依赖关系A而不是获得编译的依赖关系.请帮忙,我怎样才能做到这一点

java maven-2 maven-assembly-plugin

10
推荐指数
1
解决办法
3万
查看次数

构建一个jar并将其包含在带有maven-assembly-plugin的zip中

我有我要建设成一个罐子,这是通过提供JAR-具有依赖性descriptorRef在pom.xml很容易一个Maven化Java项目(Maven2的).

但是,我还需要在一个带有一些.exe和.bat文件的zip文件中部署我的项目,其中包括调用jar的bin文件夹.(我正在使用Tanuki,但对于我认为的用例并不重要)

换句话说,我需要一个构建,其中首先将我的源(和依赖项)打包到一个jar中,然后将该jar放入带有bin文件夹中的一些附加文件的zip.

我应该把什么放在我的pom.xml和'assembly'.xml中?

maven-2 build maven-assembly-plugin

10
推荐指数
1
解决办法
7945
查看次数

maven assembly throw stackoverflowerror

嗨,stackoverflow的居民,

我遇到了maven的问题,特别是在装配阶段.我有一个大型多模块遗留项目,遗憾的是在其子模块中有一些循环引用.它已被改装为使用maven构建,但重构循环引用将花费太长时间.

通过运行mvn install可以很好地构建项目,甚至可以毫无问题地运行mvn包,但是在运行mvn package assembly:assembly时会失败.尝试使用程序集运行它:单个给我一个构建失败,因为"创建程序集存档distrib时出错:你必须至少设置一个文件".

使用assembly:assembly,它似乎一遍又一遍地处理相同的库,最终抛出stackoverflower错误.我猜这意味着模块中的循环引用正在引起这种情况,尽管因为它没有任何问题,我希望它能够在组装过程中存活下来.

还有其他原因吗?

该项目的结构如下:

Parent
 |_ Child1
 |_ Child2
 |_ dist-proj
Run Code Online (Sandbox Code Playgroud)

父pom有以下部分:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2.1</version>
    <configuration>
        <descriptors>
            <descriptor>src/main/assembly/assembly-dependencies.xml</descriptor>
        </descriptors>
    </configuration>
</plugin>
<modules>
    <module>Child1</module>
    <module>Child2</module>
    <module>dist-proj</module>
</modules>
Run Code Online (Sandbox Code Playgroud)

分歧:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2.1</version>
    <executions>
        <execution>
            <id>dist-proj</id>
            <phase>assembly</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <descriptors>
                    <descriptor>src/main/assembly/assembly-dependencies.xml</descriptor>
                </descriptors>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

和汇编文件:

<moduleSets>
    <moduleSet>
    <useAllReactorProjects>true</useAllReactorProjects>
    <includes>
        <include>groupid:Child1</include>
        <include>groupid:Child2</include>
     </includes>
          <binaries>
             <outputDirectory>${project.build.finalName}</outputDirectory>
             <unpack>false</unpack>
             <dependencySets>
                <dependencySet>
                   <includes/>
                   <scope>compile</scope>
                </dependencySet>
                <dependencySet>
                   <includes/>
                   <scope>runtime</scope>
                   <useTransitiveFiltering>true</useTransitiveFiltering>
                </dependencySet>
             </dependencySets>
       </binaries>
    </moduleSet>
</moduleSets>
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感谢.

stack-overflow maven maven-assembly-plugin

10
推荐指数
2
解决办法
8586
查看次数

如何通过maven创建zip文件时排除一些文件夹

<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/assembl/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>bin</id>
    <baseDirectory>/</baseDirectory>
    <formats>
      <format>zip</format>
    </formats>
    <fileSets>
      <fileSet>
         <directory>src/main</directory>
         <outputDirectory>/</outputDirectory>
         <excludes>
            <exclude>src/main/dml</exclude>
         </excludes>
      </fileSet>
    </fileSets>
    </assembly>
Run Code Online (Sandbox Code Playgroud)

这是我的assemble.xml.src/main包含几个文件夹.我想排除一些文件夹,如src/main/dml,但它没有被排除.

maven maven-assembly-plugin

10
推荐指数
1
解决办法
1万
查看次数

使用maven程序集插件解压缩tar时如何保留符号链接

我正在写一个maven程序集描述符,其中一个任务是下载一个tar文件,在创建许多组件的最终tarball之前将其解压缩.

我无法弄清楚如何使用maven程序集插件保留tar中的符号链接.以前有人见过这个问题吗?

<assembly>
    <id>myassembly</id>
    <formats>
            <format>dir</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
            <dependencySet>
                    <useProjectArtifact>false</useProjectArtifact>
                    <outputDirectory>.</outputDirectory>
                    <unpack>true</unpack>
            </dependencySet>
    </dependencySets>

</assembly>
Run Code Online (Sandbox Code Playgroud)

maven-2 maven-3 maven maven-assembly-plugin

10
推荐指数
2
解决办法
3012
查看次数

maven汇编,避免zip文件中的完整路径?

我有一个多模块项目,其中包含2个模块(每个模块都有自己的pom.xml)和一个指向这些模块的父pom.xml.

当我在父pom上运行"mvn clean package"时,每个项目最终都会在它自己的目标文件夹下面有一个zip文件.我想在zip文件的根文件夹下打包一个包含每个模块zip文件的zip文件,但是我遇到了一些问题.

我在父pom.xml文件夹中创建了一个程序集文件:

<!-- Release distribution -->
<assembly>
<id>release</id>
<formats>
    <format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>

<fileSets>
    <fileSet>
        <directory>${basedir}/projectA/target/</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>*.tar.gz</include>
        </includes>
    </fileSet>
    <fileSet>
        <directory>${basedir}/projectB/target/</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>*.tar.gz</include>
        </includes>
    </fileSet>
</fileSets>
</assembly>
Run Code Online (Sandbox Code Playgroud)

虽然上述工作,如果我们开始向这个项目添加越来越多的模块,那么必须不断更新这个程序集会非常烦人.

理想情况下,我希望它能自动进入模块的每个目标文件夹并在那里获得一个zip文件.

这可以通过这样做来完成

...
<fileSet>
        <directory>${basedir}</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**/target/*.tar.gz</include>
        </includes>
    </fileSet>
Run Code Online (Sandbox Code Playgroud)

但是这里的问题是zip文件将包含完整路径,所以不是在根文件夹中有zip文件,zip文件将有projectA/target/xxxx.zip和projectB/target/xxxx.zip这正是我做的不想.

有没有办法在maven中进行简单的程序集,所以每次添加新模块时都不需要更新它,而且zip中没有完整的路径?

编辑1

看起来这根本不可能.要么你得到一个结构良好的zip文件与一个难以维护的程序集,或者你得到一个易于维护但令人讨厌的结构化zip文件.在我能找到合适的解决方案之前,我将不予回答

编辑2

回来为此寻找解决方案.关于下面发布的khmarbaise解决方案,它有一些问题: - 它依赖于依赖的程序集,在我的情况下我只想要一个程序集的程序集(更像是fileSets而不是依赖集) - 它依赖于我手动的事实指定我想要包含在程序集中的项目.我已经在父pom中有这个信息,它指定了应该构建哪些模块,所以如果我从父pom中删除一个模块以便它不再构建,程序集应该已经知道并跳过选择该项目(原因fileset似乎工作得很好,除了程序集zip中的shitty,不可控制的路径).

没有人真的遇到过类似的问题吗?

maven-3 maven maven-assembly-plugin

10
推荐指数
1
解决办法
8313
查看次数

使用自定义程序集描述符将类路径添加到清单

我有以下自定义程序集:

<assembly>
    <id>full</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>${project.build.outputDirectory}</directory>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>
Run Code Online (Sandbox Code Playgroud)

以下配置部分:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <descriptors>
            <descriptor>src/main/assembly/assembly.xml</descriptor>
        </descriptors>
        <archive>
            <manifest>
                <mainClass>com.example.MyExample</mainClass>
                <addClasspath>true</addClasspath>
                <classpathPrefix>./lib/</classpathPrefix>
            </manifest>
        </archive>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

根据有关maven程序集插件的文档,这应该将一个类路径项添加到清单文件中,但它不起作用.如果我使用已弃用的程序集目标而不是单个目标,它确实有效.

我注意到有人提到存档部分只有jar格式,但这就是我正在使用的.

当他们弃用程序集:汇编时,他们是否定义了一种正确执行此操作的新方法?我真的不喜欢使用已弃用的功能,但如果它们破坏了工作方式并且没有正确记录它,我真的不知道如何避免这种情况.

有没有人有任何正确的例子?

classpath maven-3 maven maven-assembly-plugin

9
推荐指数
1
解决办法
2万
查看次数

如何使用Maven创建具有完整依赖关系的独立应用程序?

我有一个使用Maven 2构建的桌面Java应用程序(但是如果有帮助的话我可以升级到Maven 3)有许多开源依赖项.我现在正尝试将其打包为独立版,以便最终用户无需安装maven或其他任何东西.

我已经成功地使用maven-assembly-plugin来构建一个包含所有依赖项的jar,但这并不是我想要的,因为在使用LGPL库时,您需要将您正在使用的库重新分发为单独的jar.

我希望Maven使用我的代码构建一个包含jar的zip,并且MANIFEST.MF引用我需要的其他jar和其他jar.这似乎是标准做法,但我看不出怎么做.

这是我的pom的摘录

     <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <compilerVersion>1.6</compilerVersion>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>-Dfile.encoding=UTF-8</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.company.widget.Main</mainClass>
                            <packageName>com.company.widget</packageName>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>com.company.widget.Main</mainClass>
                            <packageName>com.company.widget</packageName>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build> 
Run Code Online (Sandbox Code Playgroud)

编辑:采取卡尔斯的想法

创建了一个名为descriptor.xml的文件

<?xml version="1.0" encoding="UTF-8"?>
<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>distribution</id> …
Run Code Online (Sandbox Code Playgroud)

java maven maven-assembly-plugin maven-jar-plugin

9
推荐指数
2
解决办法
1万
查看次数

我想从我的jar中排除一些类文件.我正在使用maven-assembly-plugin.它仍然添加文件.我没有收到任何错误

我没有得到这个代码的任何错误.只是我想要排除的文件仍然被添加.我正在使用maven插件进行eclipse

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
        <execution>
            <id>only</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.Main</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <excludes>
                    <exclude>**/com/uiservices/controllers/*.*      </exclude>
                </excludes>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

jar maven maven-assembly-plugin

9
推荐指数
1
解决办法
1万
查看次数

Spring Boot uber jar打包类到root而不是BOOT-INF/classes

嗨春季启动专家 -

我正在尝试创建一个需要部署到apache风暴集群的spring boot uber jar.但是,问题在于,当使用"spring-boot-maven-plugin"打包时,Storm正在期望jar的根目录中的所有类文件,而打包的app文件在"BOOT-INF/classes"下.

有没有办法让我的应用程序类直接打包在根目录下而不是"BOOT-INF/classes"?

我尝试使用"maven-assembly-plugin"和"spring-boot-maven-plugin",如下所示,它创建了Uber jar,包含来自uber jar根目录的依赖jar中的所有类文件,但是app类仍然在BOOT-INF/classes.

<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <excludes>
                <exclude>
                    <groupId>org.apache.storm</groupId>
                    <artifactId>storm-core</artifactId>
                </exclude>
            </excludes>
            <requiresUnpack>
                <dependency>
                    <groupId>com.myorg</groupId>
                    <artifactId>my-app-artifact</artifactId> <!-- This does not help! :( -->
                </dependency>
            </requiresUnpack>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
            <appendAssemblyId>false</appendAssemblyId>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)

spring maven maven-assembly-plugin spring-boot apache-storm

9
推荐指数
1
解决办法
6658
查看次数