【发布时间】:2016-11-03 19:58:22
【问题描述】:
我可能完全误解了 Maven 的工作原理,但我有以下问题。 我在 netbeans 中使用 maven 创建了一个应用程序。它在 netbeans 中运行良好,但是当我进行 Clean and Build 时,它只是编译我的源文件,并且 maven 依赖项不在 jar 文件中,因此无法在命令窗口中运行。
这是我的 pom 文件。它有构建部分,依赖项在 mainfest.mf 的类路径中
<?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>com.ibh</groupId>
<artifactId>SafePassword</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.ibh.safepassword.TestMain</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.192</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>4.2.0.Final</version>
<type>jar</type>
</dependency>
</dependencies>
<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>
</properties>
我来自 c# 世界,认为 maven 与仅在 DEV 阶段玩游戏的 NuGet 相似,但在编译时一切都在那里......
缺少什么?如何执行 jar 文件以使其他依赖项到位,以便应用程序可以运行?
感谢您的提示!
编辑
我不同意这个问题与您所指的问题完全重复。 因为我可以阅读这些许多解决方案,所以 maven 非常复杂,每个问题都没有一个解决方案
【问题讨论】:
-
解压 jar。依赖项应该在里面。您可以使用
java -jar <jarname>运行 jar -
Sean Patrick Floyd:我检查了 jar 的内容,那里没有依赖项。在命令窗口中执行 jar 时也会得到 NoClassDefFoundError