在maven shade插件中包含依赖项

时间:2016-03-18 19:49:48

标签: java apache maven maven-shade-plugin

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

    <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库。有什么我做错了吗?

1 个答案:

答案 0 :(得分:3)

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

<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>