Maven: include folder in resource folder in the war build

醉酒当歌 提交于 2019-12-10 14:25:12

问题


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.


回答1:


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.

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.

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>

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

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



回答2:


These jars should be added as Maven dependencies, not by copying them into the lib folder. This is the sort of thing Maven is designed for.



来源:https://stackoverflow.com/questions/22198100/maven-include-folder-in-resource-folder-in-the-war-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!