有没有办法使用onejar-maven-plugin向JAR文件清单添加任意类路径条目?
我找到了configure maven-jar-plugin to do this的方式,但是似乎没有一个这样的选择for onejar-maven-plugin.
解决方法
一个jar包的使用是否真的需要?
您可以实现相同的目标(包装在一个单一的jar您的应用程序和所有必需的依赖关系,包括传递性,并添加类路径和配置使用更稳定/标准的插件)应用以下方法:
您可以实现相同的目标(包装在一个单一的jar您的应用程序和所有必需的依赖关系,包括传递性,并添加类路径和配置使用更稳定/标准的插件)应用以下方法:
>使用Maven Jar Plugin和问题中提到的approach在应用程序Jar中配置Class-Path条目
>使用Maven Assembly Plugin打包一个单一的JAR,包括依赖关系,如here所述,在另一个stackoverflow问题/答案中.
one-jar可执行文件(不使用one-jar插件)的示例可以如下:
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <!-- your further configuration here -->
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <mainClass>com.sample.MainApp</mainClass>
- <!-- your further configuration here -->
- </manifest>
- </archive>
- <descriptorRefs>
- <descriptorRef>jar-with-dependencies</descriptorRef>
- </descriptorRefs>
- </configuration>
- <executions>
- <execution>
- <id>make-assembly</id>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
如果你需要进一步玩classpath和Maven,我建议还要检查这个问题here在stackoverflow.