我的java项目不大,实际上它是一个研究项目,我正在使用一些无法由maven导入的eclipse jar。所以我只是将它们放在资源文件夹中并创建依赖项。 但是当我打包时,一切都出错了。它要么不包含那些依赖项,要么不包括我的src文件夹(!)。
我的项目结构是:
的src / COM / MYNAME /主要
resources / jar1 jar2
我使用jar-with-dependencies描述符,但我似乎迷失了它。我如何解决它?现在我的src在结果jar中丢失了。
我的pom.xml是
<?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>groupId</groupId>
<artifactId>MyProgram</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>controller.MainController</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/resources/org.eclipse.swt.win32.win32.x86_64_3.106.2.v20171129-0543.jar
</systemPath>
</dependency>
<dependency>
<groupId>swing2swt</groupId>
<artifactId>swing2swt</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/resources/swing2swt.jar</systemPath>
</dependency>
<dependency>
<groupId>org.eclipse.ui</groupId>
<artifactId>ide</artifactId>
<version>3.2.1-M20060915-1030</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.swt</artifactId>
<version>3.106.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
</project>
答案 0 :(得分:0)
为了将项目及其依赖项聚合到单个可分发的JAR文件中,您可以使用Apache Maven Assembly Plugin。典型配置如下:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<!-- NOTE: We don't need a groupId specification because the group is
org.apache.maven.plugins ...which is assumed by default.
-->
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
[...]
</project>
Here是一个示例用法。