2017-03-29 60 views
0

我有以下结构的项目。如何使用Maven Assembly插件将文件从webapp目录添加到jar中?

Project structure

我想创建一个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> 

任何帮助表示赞赏。

+0

,如果你需要的webapp目录是罐子的一部分,你为什么不把它在Java下或资源目录? –

+0

我可以为'config'目录做这件事,但是我们的项目结构就像我们有一个父项目和几个子项目一样,我们创建一个子项目的jar并把它放到父项目中,然后父项目解压缩html和其他静态内容,这就是为什么我想从wepapps目录创建一个包含目录的jar文件的原因 –

+0

它是否必须是一个jar文件?一个zip文件可以更容易创建 –

回答

0

我不知道它是可以使用Assembly插件你想要的方式,但你可以定义webapp目录作为模块的这样的资源:在这种情况下,罐子

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

那将被创建,将包括编译的代码和webapp目录。 (如果需要的话您可以添加更多信息,更多的包括其他的资源目录。

,看到https://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html

+0

Hii @Tidhar,它的工作。我知道它超出范围,但你能告诉我怎样才能生成相同的源代码jar吗? –

+0

我会检查这样的东西https://maven.apache.org/plugin-developers/cookbook/attach-source-javadoc-artifacts.html –

相关问题