首页 文章

在Maven JAR包中包含文件

提问于
浏览
0

我有一个具有以下结构的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

我希望maven jar插件在构建JAR文件时打包在数据库文件夹中 . 我已尝试按照此处所述进行包括:https://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html,但它不包含任何类或资源(之前包括它们) .

那么我应该在maven jar插件的配置中有什么?哪个是正确的包含路径以及如何保留之前包含的文件?

谢谢

1 回答

  • 0

    默认情况下,仅在JAR中添加位于 src/main/resources 中的资源 .
    您通过配置 maven-jar-plugin 尝试执行的操作仅定义要在构建的JAR中排除或包含的文件集 .
    但是这些文件仍然必须位于Maven查找资源的资源文件夹中 .

    因此,您有两种方法可以解决您的需求:

    • 在标准目录中移动 databasesrc/main/resources .

    • 为资源指定了两个 resource 文件夹:

    To do the latter,在pom.xml中添加 build 标记:

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

    然后在 database-resources 中添加您想要包的 database 文件夹 .

相关问题