Maven:在war build中的资源文件夹中包含文件夹 [英] Maven: include folder in resource folder in the war build

查看:249
本文介绍了Maven:在war build中的资源文件夹中包含文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在src / main / rescource中有一个名为extra-jars的文件夹,但是如何在构建中包含这些文件夹呢?我希望它们与其余的jar放在lib文件夹中。我尝试将它们包括在内,但是没有用。

I've a folder named extra-jars in the src/main/rescource, but how can I include these in the build? I want them to be put in the lib folder with the rest of the jars. I tried including them through , but that didnt work.

推荐答案

对于不是由Maven存储库分发的jar,最简单的方法将额外的jar放在项目的 src / main / webapp / WEB-INF / lib 目录中。按照惯例,Maven将包含最终战争神器中 src / main / webapp 下的所有内容。

For jars that are not distributed by a Maven repository, the simplest way is place the extra jars in the src/main/webapp/WEB-INF/lib directory of your project. Maven will by convention, include everything under the src/main/webapp in the final war artifact.

另外一个方法是使用 Maven War Plugin 。它能够添加其他文件通过插件配置进入最终战争神器。

An additional method is to use the Maven War Plugin. It has the ability to add additional files to the final war artifact though plugin configuration.

在POM的构建部分添加如下内容:

In the build section of the POM add something like the following:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>2.4</version>
      <configuration>
        <webResources>
          <resource>
            <directory>src/main/resource/extra-jars</directory>
            <includes>
              <include>*.jar</include>
            </includes>
            <targetPath>WEB-INF/lib</targetPath>
          </resource>
        </webResources>
      </configuration>
    </plugin>
  </plugins>
</build>

< configuration> 部分是添加其他文件的关键。

The <configuration> section is the key to adding additional files.


  • < directory> 元素定义来源资源的位置。路径相对于 pom.xml

  • < includes> element定义要包含在上面目录中的文件。

  • < targetPath> 元素定义WAR中的目标目录文件被复制到哪里。

  • The <directory> element defines the source location of the resource. The path is relative to pom.xml.
  • The <includes> element defines what files found in the above directory to include.
  • The <targetPath> element defines the destination directory in the WAR to which the files are copied.

这篇关于Maven:在war build中的资源文件夹中包含文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆