如何使用Maven Assembly插件将文件从webapp目录添加到jar?

时间:2017-03-29 09:43:59

标签: maven jar

我有以下结构的项目。

Project structure

我想创建一个具有'config'和'static'目录的jar。该jar也应该有编译类。

到目前为止,我已尝试过但没有成功。

<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>src</id>
  <formats>
    <format>jar</format>
  </formats>
  <fileSets>
    <fileSet>
        <directory>${basedir}</directory>
        <outputDirectory/>
        <includes>
            <include>src/main/webapp/config/</include>
        </includes>
    </fileSet>
</fileSets>
</assembly>

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我不确定是否可以按照您的方式使用程序集插件,但您可以将webapp目录定义为模块的资源,如下所示:

<build>
        <resources>
            <resource>
                <directory>src/main/</directory>
                <includes>
                    <include>webapp/**/*</include>
                </includes>
            </resource>
        </resources>
</build>

在这种情况下,将创建的jar将包括已编译的代码和webapp目录。 (如果需要,您可以添加更多内容以包含其他资源目录。

有关详细信息,请参阅https://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html