不能依赖maven程序集插件 [英] cannot recup dependency with maven assembly plugin

查看:122
本文介绍了不能依赖maven程序集插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了maven程序集插件的问题,我无法理解为什么。

I have a problem with maven assembly plugin, and I cannot understand why.

我希望创建一个可执行jar,但生成的jar中缺少一些东西。

I wish to create an executable jar but there is something missing in the generated jar.

实际上,生成的jar不包含pom(common-loggins)中实际引用的依赖项,而生成的jar中存在所有其他依赖项。

Actually, the generated jar does not contain a dependency which is actually refered to in the pom (common-loggins), whereas all other dependencies are present in the generated jar.

执行jar时,我在commons-logging类上得到一个NoClassDefError。

At the execution of the jar, I get a "NoClassDefError" on the commons-logging class.

我已经包含了一个简化的pom,所以你可以测试看看问题。

I have included a simplified pom, so you can test to see the problem.

PARENT POM在commons-loggin上有一个管理的依赖性

THE PARENT POM HAS A MANAGED DEPENDENCY ON commons-loggin

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>fr.home.ig.control</groupId>
    <artifactId>control</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>ig-bacth</artifactId>
<name>ig-batch</name>
<description>batch de l'application control</description>
<packaging>jar</packaging>

<dependencies>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.3</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.5</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>fr.home.ig.control.batch.BatchManager</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-jar-with-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

推荐答案

我不太了解这个插件,但您可能想要考虑。

I do not know so good this plugin, but there is a possibility that you maybe want to consider.

使用shade插件代替程序集插件。 http://maven.apache.org/plugins/maven-shade-plugin/

Instead of the assembly plugin, use shade plugin. http://maven.apache.org/plugins/maven-shade-plugin/

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                        <exclude>.settings/**</exclude>
                                        <exclude>*.classpath</exclude>
                                        <exclude>*.project</exclude>
                                        <exclude>*.txt</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

并创建一个完整的.exe,包括全部启动.jar的所有或.exe,使用launch4j插件 https://github.com/lukaszlenart/launch4j-maven-plugin

And to create a whole .exe including all, or .exe which launch a .jar with all, use launch4j plugin https://github.com/lukaszlenart/launch4j-maven-plugin

           <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
                <version>1.5.2</version>
                <executions>
                    <execution>
                        <id>l4j-gui</id>
                        <phase>package</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>gui</headerType>
                            <outfile>target/Project.exe</outfile>
                            <jar>target/${project.artifactId}-${project.version}.jar</jar>
                            <!-- if <dontWrapJar>true</dontWrapJar> change to this conf <jar>${project.artifactId}-${project.version}.jar</jar> -->
                            <dontWrapJar>false</dontWrapJar>
                            <errTitle>Error in launch4j plugin</errTitle>
                            <classPath>
                                <mainClass>path.Main</mainClass>
                            </classPath>
                            <icon>Project.ico</icon>
                            <jre>
                                <minVersion>1.5.0</minVersion>
                                <maxVersion>1.6.0</maxVersion>
                                <initialHeapSize>512</initialHeapSize>
                                <maxHeapSize>1024</maxHeapSize>
                            </jre>
                            <versionInfo>
                                <fileVersion>1.0.0.0</fileVersion>
                                <txtFileVersion>1.0.0.0</txtFileVersion>
                                <fileDescription>des</fileDescription>
                                <copyright>Copyright (c) 2014 </copyright>
                                <companyName>comp</companyName>
                                <productVersion>3.0.0.0</productVersion>
                                <txtProductVersion>${project.version}</txtProductVersion>
                                <productName>Project</productName>
                                <internalName>Project</internalName>
                                <originalFilename>Project.exe</originalFilename>
                            </versionInfo>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

这篇关于不能依赖maven程序集插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆