我正在使用由Maven管理的Java项目。我想用Maven自动创建项目的.jar文件,这样在Maven执行任务之后会有这样的事情:
directory_i_want_to_create
my_project.jar
config.json
input_folder
由于我的项目需要如上所述从输入文件夹和config.json读取输入(以便我可以运行命令行来执行jar),如何使用Maven创建如上所述的directory_i_want_to_create
? / p>
答案 0 :(得分:0)
我会推荐一个Assembly Plugin。配置如下:
<强>的pom.xml 强>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/default.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
...
<强> default.xml中强>
<?xml version="1.0"?>
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>default</id>
<formats>
<format>dir</format>
</formats>
<dependencySets>
<dependencySet>
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>directory_i_want_to_create</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<outputDirectory>input_folder</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
</fileSets>
</assembly>