原文链接:http://blog.csdn.net/u012849872/article/details/51035938

maven工程标准目录结构: 
src 
   -main 
      –bin 脚本库 
      –java java源代码文件 
      –resources 资源库,会自动复制到classes目录里 
      –filters 资源过滤文件 
      –assembly 组件的描述配置(如何打包) 
      –config 配置文件 
      –webapp web应用的目录。WEB-INF、css、js等 
  -test 
    –java 单元测试java源代码文件 
    –resources 测试需要用的资源库 
    –filters 测试资源过滤库 
  -site Site(一些文档) 
target 
LICENSE.txt Project’s license 
README.txt Project’s readme 
target是有存放项目构建后的文件和目录,jar包、war包、编译的class文件等。 
target里的所有内容都是maven构建的时候生成的


问题说明: 
在打包 war 包的时候,普通情况下只会打包src/main/resources下面的资源文件,在开发过程中我们也会把需要的配置文件放在这个目录下。但是有些情况下会和 java文件放在同一个目录下,比如 hibernate 的映射文件 .hbm.xml,还有 mybatis 的 *mapper.xml文件,一般情况都会和对应的 *VO.java 放在同一个目录下。这样利用maven打包时,就需要修改pom.xml文件,来把mapper.xml文件一起打包进jar或者war里了,否则,这些文件不会被打包的。(maven认为src/main/java只是java的源代码路径)。 
下面是我的工程目录,我想要把mapping 里的.xml文件打入 war包,都是mybatis的映射文件,通过测试下面这三种方式都可以: 
 
方法一:直接在 标签里添加

 <build>
<finalName>SSMDemo</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

方法二:利用build-helper-maven-plugin插件

<plugs>
<!--
此plugin可以用
利用此plugin,把源代码中的xml文件,
打包到相应位置,这里主要是为了打包Mybatis的mapper.xml文件
-->
<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>
<plugs>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

方法三:利用maven-resources-plugin插件

<plugins>
<!--
此plugin可以用
利用此plugin,把源代码中的xml文件,打包到相应位置,
这里主要是为了打包Mybatis的mapper.xml文件
-->
<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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

以上参考文档: 
http://bglmmz.iteye.com/blog/2063856

maven工程标准目录结构: 
src 
   -main 
      –bin 脚本库 
      –java java源代码文件 
      –resources 资源库,会自动复制到classes目录里 
      –filters 资源过滤文件 
      –assembly 组件的描述配置(如何打包) 
      –config 配置文件 
      –webapp web应用的目录。WEB-INF、css、js等 
  -test 
    –java 单元测试java源代码文件 
    –resources 测试需要用的资源库 
    –filters 测试资源过滤库 
  -site Site(一些文档) 
target 
LICENSE.txt Project’s license 
README.txt Project’s readme 
target是有存放项目构建后的文件和目录,jar包、war包、编译的class文件等。 
target里的所有内容都是maven构建的时候生成的


问题说明: 
在打包 war 包的时候,普通情况下只会打包src/main/resources下面的资源文件,在开发过程中我们也会把需要的配置文件放在这个目录下。但是有些情况下会和 java文件放在同一个目录下,比如 hibernate 的映射文件 .hbm.xml,还有 mybatis 的 *mapper.xml文件,一般情况都会和对应的 *VO.java 放在同一个目录下。这样利用maven打包时,就需要修改pom.xml文件,来把mapper.xml文件一起打包进jar或者war里了,否则,这些文件不会被打包的。(maven认为src/main/java只是java的源代码路径)。 
下面是我的工程目录,我想要把mapping 里的.xml文件打入 war包,都是mybatis的映射文件,通过测试下面这三种方式都可以: 
 
方法一:直接在 标签里添加

 <build>
<finalName>SSMDemo</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

方法二:利用build-helper-maven-plugin插件

<plugs>
<!--
此plugin可以用
利用此plugin,把源代码中的xml文件,
打包到相应位置,这里主要是为了打包Mybatis的mapper.xml文件
-->
<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>
<plugs>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

方法三:利用maven-resources-plugin插件

<plugins>
<!--
此plugin可以用
利用此plugin,把源代码中的xml文件,打包到相应位置,
这里主要是为了打包Mybatis的mapper.xml文件
-->
<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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

以上参考文档: 
http://bglmmz.iteye.com/blog/2063856

maven打包资源文件(转)的更多相关文章

  1. Maven 包含资源文件

    Maven打包时,如何包含资源文件(src/main/java | src/main/resources): 参考博客:http://blog.csdn.net/jsflzhong/article/d ...

  2. Pyqt 打包资源文件

    用打包工具将做好的Pyqt程序打包成exe后发现引用的资源图片都显示不了? 是否遇到了和我一样的问题呢.google之后找到了方法,一种方法是在程序中引用外部资源,另外一种方法是将资源文件转换为py文 ...

  3. VS打包资源文件,转自推酷,请小星同学查看

    上篇博客把收费系统的总体设计进行了一遍讲解,讲解的同时掺杂了些有关.NET编译机制的总结.程序编写测试完成后接下来我们要做的是打包部署程序,但VS2012让人心痛的是没有了打包工具.不知道出于什么原因 ...

  4. Webpack 使用url-loader和file-loader打包资源文件

    在js中不仅可以通过import引入js文件,还可以引入图片.视频等资源文件,这样webpack打包时就会把所引入的资源文件也一起打包进来 打包进来的文件会返回一个字符串:即文件的路径 要做到这一点, ...

  5. pyinstall打包资源文件

    相关代码 main.py import sys import os #生成资源文件目录访问路径 #说明: pyinstaller工具打包的可执行文件,运行时sys.frozen会被设置成True # ...

  6. 记一次maven打包编译文件一直不正确

    maven打包发现war包解压后的class文件总是跟原Java不一样 后来发现pom中这么写到 <plugins> <plugin> <artifactId>ma ...

  7. maven 打包 xml文件

    说起来手贱啊,搞了两个小时,就是因为打包的时候,maven无法把xml文件打包到正确的位置. 本来应该是打包到 com/presistence包下,结果打出来有两个包,一个是com/presisten ...

  8. Maven让资源文件处理插件能够解析资源文件中的Maven属性

    <build> <resources> <resource> <directory>${project.basedir}/src/main/resour ...

  9. Maven编译资源文件拷贝

    <build> <finalName>op-balance-job-service</finalName> <plugins> <plugin&g ...

随机推荐

  1. Android仿今日头条手界面

    public class MyIndicator extends HorizontalScrollView implements ViewPager.OnPageChangeListener { pr ...

  2. android唯一设备标识、设备号、设备ID的获取方法

    ##如何获取Android设备唯一ID? ###问题 每一个android设备都有唯一ID吗?如果有?怎么用java最简单取得呢? ###回答1(最佳) 如何取得android唯一码? 好处: 1.不 ...

  3. HDU1757:A Simple Math Problem(矩阵快速幂)

    http://acm.hdu.edu.cn/showproblem.php?pid=1757 Problem Description Lele now is thinking about a simp ...

  4. SCons构建工具使用

    scons是一个Python写的自动化构建工具,和GNU make相比优点明显:    1. 移植性:python能运行的地方,就能运行scons    2. 扩展性:理论上scons只是提供了pyt ...

  5. virtulenv使用

    windows下创建虚拟环境 安装 virtualenv pip3 install virtualenv #选择一个存放虚拟环境的文件夹 cmd中 d: mkdir xxx cd xxx # 创建虚拟 ...

  6. PHP开发之thinkPHP分层设计

    thinkphp模型层Model.Logic.Service讲解        ThinkPHP支持模型的分层 ,除了Model层之外,我们可以项目的需要设计和创建其他的模型层. 通常情况下,不同的分 ...

  7. P1879 [USACO06NOV]玉米田Corn Fields(状压dp)

    P1879 [USACO06NOV]玉米田Corn Fields 状压dp水题 看到$n,m<=12$,肯定是状压鸭 先筛去所有不合法状态,蓝后用可行的状态跑一次dp就ok了 #include& ...

  8. 一个Golang例子:for + goroutine + channel

    Rob Pike 在 Google I/O 2012 - Go Concurrency Patterns 里演示了一个例子(daisy chain). 视频地址:https://www.youtube ...

  9. eclipse 项目svn忽略不需要提交的文件

    1.eclipse选择window–>Prenference 2.选择Team–> Git下面的Ignoreed Resources –>Add Pattern –>一个一个的 ...

  10. Xshell5 访问虚拟机Ubuntu16.04

    1.Ubuntu安装telnet 安装openbsd-inetd sudo apt-get install openbsd-inetd 安装telnetd sudo apt-get install t ...