我有一个包含 hadoop 的 map/reduce 代码的 jar。它需要一个依赖项,我需要将其放入 jar 的 lib 目录中,以便 jar 是自包含的并且可以在 hadoop 中工作。
这就是我在我的 pom 中所做的:
1)添加 maven-dependency-plugin 将我需要的库复制到 target/lib 文件夹中
2)配置jar插件以获取target/lib文件夹中的libs,并将其添加到生成的jar中。
我只是无法让它工作。生成的 jar 不包含额外的库。
我还尝试将 target/lib 目录添加到 pom 中的 / 标记中,但这也不起作用。
这是我的pom,带注释....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy apache-httpcomponents</id>
<phase>process-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeTypes>jar</includeTypes>
<includeGroupIds>org.apache.httpcomponents</includeGroupIds>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<stripVersion>false</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>add lib directory to jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>jar</classifier>
<includes>
<include>${project.build.outputDirectory/lib/**</include>
<include>${project.build.outputDirectory/target/**</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
任何帮助表示赞赏!