简体   繁体   中英

Include files in Maven JAR package

I have a maven project with the following structure:

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. 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).

So what should I have in the configuration of the maven jar plugin? 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.
What you tried to do by configuring the maven-jar-plugin defines only the filetset to exclude or include in the built JAR.
But these files still have to be located in a resources folder where Maven looks for resources.

So, you have two ways to solve your requirement:

  • move database in the standard directory : src/main/resources .

  • specifies two resource folders for resources :

To do the latter , in the pom.xml add in the build tag :

<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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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