maven程序集创建具有依赖项和类路径的jar [英] maven assembly create jar with dependency and class path
问题描述
我有一个有很多依赖项的maven项目。
我想使用程序集插件将所有依赖jar包装在一个带有依赖关系的jar中,但我并不是所有的依赖关系都不会在一个大混乱中解压缩。我希望他们所有人都进入lib文件夹,但我不知道如何添加类路径。
我的pom:
I have a maven project with a lot of dependencies. I want to pack all in a jar with dependency using assembly plugin, but I don't won't all the dependencies jars unpacked in a big mess. I want all of them do go into lib folder, but I don't know how to add the class path. my pom:
<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>test.com</groupId>
<artifactId>simple-weather</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>simple-weather</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>adi.com.weather.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>package.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
</project>
我的汇编文件
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>test5</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>false</unpack>
<scope>runtime</scope>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
推荐答案
如果maven-jar-plugin没有生成条目清单文件中的Class-Path尽管已设置< addClasspath> true< / addClasspath>
,但请确保您使用的是2.2或更新版本的插件。
If maven-jar-plugin is not generating the entry Class-Path in the manifest file although you have set <addClasspath>true</addClasspath>
, make sure you are using version 2.2 or newer of the plugin.
MJAR-83 <版本2.1中的/ a>阻止插件在类路径中列出依赖项。
It seems that the bug MJAR-83 in version 2.1 was preventing the plugin from listing the dependencies in Class-Path.
这篇关于maven程序集创建具有依赖项和类路径的jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!