【发布时间】:2016-03-23 01:08:39
【问题描述】:
所以我在eclipse中有一个小型maven项目,如果我导出一个可运行的JAR并选择:
- 将所需的库打包到生成的 JAR 中
它工作正常。
我应该注意,我的一个 JAR 是 maven 控制的(Univocity),另一个是本地 Oracle JDBC JAR。我想将这两个都包含在我的可运行 JAR 包中,这样我就可以将单个 JAR 部署到生产环境并使用单个命令执行它。
在我的 POM 中,我添加了 maven-assembly-plugin,当我使用 mvn 包时,我得到了一个带有 Univocity 库的 JAR,但它跳过了 Oracle JAR。
如何将 Oracle JAR 捆绑到最终输出中?
这是 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>au.com.myco</groupId>
<artifactId>MyCoOracleExtractor</artifactId>
<version>0.0.4</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<univocity.version>2.0.0</univocity.version>
</properties>
<dependencies>
<dependency>
<groupId>oracle.jdbc</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
<type>jar</type>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ojdbc6-11.2.0.4.jar</systemPath>
</dependency>
<dependency>
<groupId>com.univocity</groupId>
<artifactId>univocity-parsers</artifactId>
<version>${univocity.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assembly:package</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>au.com.myco.MyCoOracleExtractor</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我确实尝试过使用 maven-dependency-plugin,但它没有解决将它们捆绑到单个 JAR 中的问题。
【问题讨论】:
-
请注意 - 当我在 eclipse 中导出可运行的 JAR 时,它包括:org.eclipse.jdt.internal.jarinjarloader。 我假设这个库处理解包捆绑的罐子。
标签: eclipse maven executable-jar