• Maven 包含资源文件


    Maven打包时,如何包含资源文件(src/main/java | src/main/resources):

      参考博客:http://blog.csdn.net/jsflzhong/article/details/52077075

       在Maven项目中,一般将用到的资源文件(xml | properties | xsd等)放在src/main/resources下面,利用Maven打包时,Maven可以将这些资源文件打包到相应的jar或者时war中

      1 可以在pom文件中进行配置:

        **/*这样的写法,是为了保证各级子目录下的资源文件都被打包

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
    </build>

       2 可以使用build-helper-maven-plugin插件

        <build>  
            <plugins>  
                <plugin>  
                    <groupId>org.codehaus.mojo</groupId>  
                    <artifactId>build-helper-maven-plugin</artifactId>  
                    <version>1.8</version>  
                    <executions>  
                        <execution>  
                            <id>add-resource</id>  
                            <phase>generate-resources</phase>  
                            <goals>  
                                <goal>add-resource</goal>  
                            </goals>  
                            <configuration>  
                                <resources>  
                                    <resource>  
                                        <directory>src/main/java</directory>  
                                        <includes>  
                                            <include>**/*.xml</include>  
                                        </includes>  
                                    </resource>  
                                </resources>  
                            </configuration>  
                        </execution>  
                    </executions>  
                </plugin>     
            </plugins>       
        </build>  

      3 可以使用maven-resources-plugin插件

    <build>  <plugins>
        <plugin>  
          <artifactId>maven-resources-plugin</artifactId>  
          <version>2.5</version>  
          <executions>  
            <execution>  
              <id>copy-xmls</id>  
                    <phase>process-sources</phase>  
                    <goals>  
                         <goal>copy-resources</goal>  
                    </goals>  
                    <configuration>  
                         <outputDirectory>${basedir}/target/classes</outputDirectory>  
                         <resources>  
                              <resource>  
                                  <directory>${basedir}/src/main/java</directory>  
                                  <includes>  
                                      <include>**/*.xml</include>  
                                   </includes>  
                              </resource>  
                         </resources>  
                    </configuration>  
                </execution>  
             </executions>  
          </plugin>     
     </plugins>       
    </build>  
  • 相关阅读:
    <JZOJ5912>VanUSee
    <JZOJ5910>duliu
    <JZOJ5913>林下风气
    pytest学习笔记(二)
    试用saucelabs进行浏览器兼容性测试
    pytest学习笔记(一)
    SSM框架搭建,以及mybatis学习
    游戏2048的python实现
    使用svn在github上下载文件夹
    jenkins集成python的单元测试
  • 原文地址:https://www.cnblogs.com/roxy/p/7650314.html
Copyright © 2020-2023  润新知