Maven-带依赖项的构建
我从互联网上下载了一个源代码,我正试图用maven构建它。以下是源代码附带的pom.xml文件:Maven-带依赖项的构建,maven,build,dependencies,Maven,Build,Dependencies,我从互联网上下载了一个源代码,我正试图用maven构建它。以下是源代码附带的pom.xml文件: <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/maven-v4_0_0.xs
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>myArtifact</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>myArtifact</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>myArtifact.Main</mainClass>
</manifest>
</archive>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>8.4-701.jdbc4</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
4.0.0
com.mycompany
我的神器
罐子
1.0-快照
我的神器
http://maven.apache.org
org.apache.maven.plugins
maven编译器插件
2.0.2
带有依赖项的jar
我的神器
1.5
1.5
postgresql
postgresql
8.4-701.jdbc4
编译
mvn install命令正在生成jar文件,但由于缺少依赖项,我无法执行此文件(本例中与postgresql依赖项相关的类未找到异常)
我注意到maven已经正确下载了依赖项(jar库都在本地maven存储库目录中),但是mvn安装没有将这些库复制到生成的jar文件中。我该怎么做
谢谢。从
maven编译器插件
部分删除描述符REFS
和存档标记
为了生成一个包含所有依赖项的JAR。您需要将其放入pom.xml
的构建插件部分:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>
com.test.your.main.class.goes.Here
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
需要在之前添加
mvn clean compile assembly:single