Maven 使用IntelliJ&;构建的可执行jar的自定义jar内容;专家
我为其构建可执行JAR文件的人希望所有外部需要的库都位于一个单独的Maven 使用IntelliJ&;构建的可执行jar的自定义jar内容;专家,maven,jar,intellij-idea,maven-2,Maven,Jar,Intellij Idea,Maven 2,我为其构建可执行JAR文件的人希望所有外部需要的库都位于一个单独的lib/目录中,当他运行我的JAR时,该目录将位于他当前的工作目录中。他还要求我从JAR中取出log4j.xml和config.properties文件,以便他可以编辑它们的值。如何使用IntelliJ和maven构建一个包含这样清单的JAR?这可以通过一些maven插件来完成 要将所有依赖项放入不同的文件夹,请使用maven依赖项插件。本例将它们放在target/lib文件夹中 <plugin> <grou
lib/
目录中,当他运行我的JAR时,该目录将位于他当前的工作目录中。他还要求我从JAR中取出log4j.xml
和config.properties
文件,以便他可以编辑它们的值。如何使用IntelliJ和maven构建一个包含这样清单的JAR?这可以通过一些maven
插件来完成
要将所有依赖项
放入不同的文件夹,请使用maven依赖项插件
。本例将它们放在target/lib
文件夹中
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
最后,您需要使用maven jar插件执行以下操作:
从jar中排除资源
引用jar清单中lib文件夹中的所有依赖项
在jar清单中引用conf文件夹中的资源
类似于以下的方法应该可以工作:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>foo.bar.Main</mainClass>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>conf/</Class-Path>
</manifestEntries>
</archive>
<classifier>jar-without-resources</classifier>
<excludes>
<exclude>log4j.properties</exclude>
<exclude>config.properties</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
org.apache.maven.plugins
maven jar插件
2.4
包裹
罐子
真的
美因酒店
解放党/
形态/
没有资源的罐子
log4j.properties
config.properties
希望这有帮助
意志
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>foo.bar.Main</mainClass>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>conf/</Class-Path>
</manifestEntries>
</archive>
<classifier>jar-without-resources</classifier>
<excludes>
<exclude>log4j.properties</exclude>
<exclude>config.properties</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>