【发布时间】:2018-09-11 01:10:18
【问题描述】:
我有一个项目,我想将其导出为 jar(由于某些原因,无法将其导出为可运行的 jar)。我有 3 个 maven 依赖项,gson、io 和 junit,但是当我在控制台中执行 maven 构建的 jar 时,它会说:
检查我的构建路径:
我以这种方式导出它(Eclipse): 运行方式 -> Maven 构建...
(mvn) package
这是我的 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>Carlos</groupId>
<artifactId>Buscaminas</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Buscaminas</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>res.application.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
</project>
【问题讨论】:
-
目前尚不清楚,但很可能您应该使用指向您放置 jar 文件的 lib 目录的类路径定义来更新清单文件。如果存在,您可以分享您的清单文件吗?
-
我通常使用
maven-shade-plugin构建uber-jar(包含依赖项)。 -
@cool 不,它似乎没有任何清单。我做了一个 mvn clean install 但仍然没有出现。
-
但是从你的截图我认为你没有使用 maven 来生成 jar。相反,您正在使用来自某个 ide 的 jar 导出器。所以你不应该使用 mvn clean install 来检查它。您应该像以前一样导出 jar。如果你想让它运行 mvn clean install 你应该使用 maven-shade-plugin 或 smth。
-
所以现在你需要添加 maven-assembly-plugin 或 maven-shade-plugin 来创建包含所有依赖项的 ueber jar 文件....maven.apache.org/plugins/maven-shade-plugin/examples/…
标签: java maven build compilation dependencies