[英]Maven package add jars from dependencies to jar
I'm trying to create a jar from my maven project containing the jar files from dependencies in a specific folder.我正在尝试从我的 maven 项目创建一个 jar,其中包含来自特定文件夹中依赖项的 jar 文件。
The framework I'm writing a plugin for requires external dependencies to be supplied as jar files in the plugin jar.我正在为其编写插件的框架需要将外部依赖项作为插件 jar 中的 jar 文件提供。
For example:例如:
xxxx.jar
/myapp/myjavaclasses
/lib/externalDependencies.jar
My pom file:我的pom文件:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>AAAAA</groupId>
<artifactId>BBBBBBB</artifactId>
<packaging>jar</packaging>
<version>1.1</version>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifestEntries>
<Rundeck-Plugin-Classnames>CCCCC</Rundeck-Plugin-Classnames>
<Rundeck-Plugin-Version>1.1</Rundeck-Plugin-Version>
<Rundeck-Plugin-Archive>true</Rundeck-Plugin-Archive>
<Rundeck-Plugin-File-Version>${project.version}</Rundeck-Plugin-File-Version>
<Rundeck-Plugin-Libs>lib/httpclient-4.5.8.jar lib/httpcore-4.4.11.jar</Rundeck-Plugin-Libs>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
In the above pom file we have the dependency在上面的 pom 文件中,我们有依赖项
org.apache.httpcomponents org.apache.httpcomponents
, this dependency contains the following jars ,这个依赖包含以下jars
httpclient-4.5.8.jar httpcore-4.4.11.jar httpclient-4.5.8.jar httpcore-4.4.11.jar
these jars need to be imported in my final jar under the folder /lib.这些 jar 需要导入到文件夹 /lib 下的最终 jar 中。
Thanks to @ernest_k came to a solution using感谢@ernest_k 找到了一个使用解决方案
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
and和
<resources>
<resource>
<directory>.</directory>
<includes>
<include>lib/**/*.jar</include>
</includes>
</resource>
</resources>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.