如何使用 Maven 在 jar 编译中包含非 java 文件?
How do I include non-java files in jar compilation using maven?
我有一个包含保存数据的 .txt 文件的文件夹。此数据加载到我的游戏中,然后在游戏中使用。
我还有 3 个不在 Maven 上的库。所以我使用这个插件将它们加载到 .m2 文件夹中:maven-install-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-everythingrs-api-jar</id>
<phase>validate</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>everythingrs-api</groupId>
<artifactId>everythingrs-api</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>${project.basedir}/lib/everythingrs-api.jar</file>
<generatePom>true</generatePom>
</configuration>
</execution>
<execution>
...
</execution>
<execution>
...
</execution>
<executions>
</plugin>
然后我使用这个插件:maven-assembly-plugin 将项目编译成一个包含其中库的 jar。
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>${main-class-path}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
现在,如果我 运行 mvn clean validate install,会将我拥有的 3 个库复制到 .m2 中,然后第二个插件将编译成一个可执行 jar,其中包含从 maven repo 导入的库和将 .m2 添加到 jar 中的 3 个库。
但是,我还有一个文件夹在项目中./ 但在 src 之外,我怎样才能让 Maven 插件也将这个 directory/folder 包含到 jar 中?
尝试使用 maven resources plugin. 它允许您将不在 /src/main/resources
下的文件夹添加为 Maven 资源。
我有一个包含保存数据的 .txt 文件的文件夹。此数据加载到我的游戏中,然后在游戏中使用。
我还有 3 个不在 Maven 上的库。所以我使用这个插件将它们加载到 .m2 文件夹中:maven-install-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-everythingrs-api-jar</id>
<phase>validate</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>everythingrs-api</groupId>
<artifactId>everythingrs-api</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>${project.basedir}/lib/everythingrs-api.jar</file>
<generatePom>true</generatePom>
</configuration>
</execution>
<execution>
...
</execution>
<execution>
...
</execution>
<executions>
</plugin>
然后我使用这个插件:maven-assembly-plugin 将项目编译成一个包含其中库的 jar。
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>${main-class-path}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
现在,如果我 运行 mvn clean validate install,会将我拥有的 3 个库复制到 .m2 中,然后第二个插件将编译成一个可执行 jar,其中包含从 maven repo 导入的库和将 .m2 添加到 jar 中的 3 个库。
但是,我还有一个文件夹在项目中./ 但在 src 之外,我怎样才能让 Maven 插件也将这个 directory/folder 包含到 jar 中?
尝试使用 maven resources plugin. 它允许您将不在 /src/main/resources
下的文件夹添加为 Maven 资源。