java在IDE外部执行maven项目
我可能完全误解了maven的工作原理,但我有以下问题。 我用netbeans中的maven创建了一个应用程序。它可以在netbeans中运行,但是当我进行清理和构建时,它只编译我的源文件,并且maven依赖项不在jar文件中,因此无法在命令窗口中运行
这是我的pom文件。它有build部分,依赖项位于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#world,认为maven与NuGet类似,后者只在开发阶段玩游戏,但在编译时一切都在那里
少了什么?如何执行jar文件,使其他依赖项就位,从而使应用程序能够运行
谢谢你的提示
编辑
我不同意这个问题与你所指的完全重复。 正如我所读到的,maven的解决方案非常复杂,没有一个解决方案可以解决所有问题
# 1 楼答案
默认情况下,Maven构建的jar基本上是一个库——它不包含依赖项。如果要包含依赖项,创建可运行的应用程序,您有两个主要选项:
war
或ear