Shade插件中包含依赖项

Shade插件中包含依赖项

本文介绍了在Maven Shade插件中包含依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Apache的commons-lang3创建一个可部署的jar.但是,我的Hadoop所在的AWS集群不包含该库,因此我得到了classNotFoundException.我想我需要手动添加该依赖关系,但是我在使用maven shade插件时遇到问题(建议使用此插件).我当前的pom文件如下所示:

I am trying to create a deploy-able jar which using Apache's commons-lang3. However my AWS cluster where my Hadoop is does not contain this library so I get a classNotFoundException. I figured I needed to manually add that dependency in but I am having issues working with the maven shade plugin (I was recommended to use this) My current pom file looks like this :

    <dependency>
        <groupId>org.apache.pig</groupId>
        <artifactId>pig</artifactId>
        <version>0.12.0-cdh5.2.6</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.4</version>
    </dependency>
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <artifact>org.apache.commons:commons-lang3</artifact>
                                <includes>
                                    <include>org/apache/commons/commons-lang3/3.4/*</include>
                                </includes>
                        <minimizeJar>true</minimizeJar>
                    </configuration>
                </execution>
            </executions>

        </plugin>

我想要一个完全普通的jar,其中嵌入了commons-lang3库.我做错了什么吗?

I want a completely normal jar with the addition of the commons-lang3 library embedded inside. Is there something I am doing incorrectly?

推荐答案

要包括列入白名单的jar,您需要执行以下操作:

To include whitelisted jars you need to do the following:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <artifactSet>
                            <includes>
                                <include>org.apache.commons:commons-lang3</include>
                            </includes>
                        </artifactSet>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

这篇关于在Maven Shade插件中包含依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 08:17