2
我正在使用下面的插件來生成可執行jar.I在我的類路徑中有一個屬性文件,我想添加到我的jar,但使用程序集插件我我無法做到這一點。我找到了一些答案,說我們可以使用jar插件創建一個jar,然後使用assembly插件打包它們。任何人都可以幫助我如何做到這一點。如何添加classpath屬性到使用maven程序集的可執行jar
我的插件描述
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>mainclass</mainClass>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<includes>
<include>myconfig.propeties</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<finalName>app</finalName>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>
mainclass
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
我的罐子與 - dependeinceis文件
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>bin</id>
<!-- Generates a zip package containing the needed files -->
<formats>
<format>zip</format>
</formats>
<!-- Adds dependencies to zip package under lib directory -->
<dependencySets>
<dependencySet>
<!--
Project artifact is not copied under library directory since
it is added to the root directory of the zip package.
-->
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
<fileSets>
<!--
Adds startup scripts to the root directory of zip package. The startup
scripts are located to src/main/scripts directory as stated by Maven
conventions.
-->
<fileSet>
<directory>${project.build.scriptSourceDirectory}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>startup.*</include>
</includes>
</fileSet>
<!-- adds jar package to the root directory of zip package -->
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
在此先感謝。
當您執行全新安裝時,目標文件夾是否包含您打算包含在JAR中的屬性文件? – ppuskar 2014-08-28 04:55:40
是的,它包含文件,但它不包含在jar中 – 2014-08-28 05:27:01