简体   繁体   English

在Maven JAR包中包含文件

[英]Include files in Maven JAR package

I have a maven project with the following structure: 我有一个具有以下结构的Maven项目:

project

-src
--main
---java
----(All my .java files are here in their packages)
---resource
----(All my resources are here)

-database (HSQLDB files)
--db.script
--db.properties
--db.data

-target
--Maven build directory

pom.xml

I want the maven jar plugin to package in the database folder when it builds a JAR file. 我希望Maven jar插件在构建JAR文件时将其打包在数据库文件夹中。 I've tried including as outlined here: https://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html , but it doesn't find the directory "../database" (or ../../database OR ../../../database!), and also it now doesn't include any of the classes or resources (It was including them before). 我已尝试按照此处所述进行添加: https ://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html,但是找不到目录“ ../ database”(或../../database或../../../database!),并且现在它不包含任何类或资源(以前包括它们)。

So what should I have in the configuration of the maven jar plugin? 那么我应该在Maven jar插件的配置中拥有什么? Which is the correct path to include and how do I keep the files it was including before? 哪个是正确的路径,如何保存以前包含的文件?

Thanks 谢谢

By default, only resources located in src/main/resources are added in the JAR. 默认情况下,仅将位于src/main/resources添加到JAR中。
What you tried to do by configuring the maven-jar-plugin defines only the filetset to exclude or include in the built JAR. 通过配置maven-jar-plugin尝试执行的操作仅定义了要排除或包含在已构建JAR中的文件集。
But these files still have to be located in a resources folder where Maven looks for resources. 但是这些文件仍必须位于Maven查找资源的资源文件夹中。

So, you have two ways to solve your requirement: 因此,您有两种方法可以解决您的需求:

  • move database in the standard directory : src/main/resources . database移动到标准目录: src/main/resources

  • specifies two resource folders for resources : 为资源指定两个resource文件夹:

To do the latter , in the pom.xml add in the build tag : 为此 ,在pom.xml中添加build标记:

<resources>
     <resource>
       <directory>src/main/resources</directory>          
     </resource>
     <resource>
       <directory>database-resources</directory>
     </resource>
</resources>

Then add the database folder that you want package inside the database-resources . 然后,将要打包的database文件夹添加到database-resources

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM