原文链接: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. 【剑指Offer】俯视50题之1-10题

    面试题1赋值运算符函数  面试题2 实现Singleton模式  面试题3 二维数组中的查找   面试题4 替换空格   面试题5 从头到尾打印链表   面试题6 重建二叉树   面试题7 用两个栈实 ...

  2. 前端错误提示whitelabel error page

    1:错误提示whitelabel error page:需要定义一个error.html  ,否则提示如图

  3. 【转】Deep Learning(深度学习)学习笔记整理系列之(三)

    好了,到了这一步,终于可以聊到Deep learning了.上面我们聊到为什么会有Deep learning(让机器自动学习良好的特征,而免去人工选取过程.还有参考人的分层视觉处理系统),我们得到一个 ...

  4. java map典型排序

    List<Map.Entry<TbDiseases, Double>> list = new ArrayList<Map.Entry<TbDiseases,Doub ...

  5. ABP常见问题

    System.Data.SqlClient.SqlException (0x80131904): 'OFFSET' 附近有语法错误 解决方案:最新的ABP默认支持的是sql2012以上的版本,对于之前 ...

  6. 2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution

    A - Odd Palindrome 水. #include <bits/stdc++.h> using namespace std; #define N 110 char s[N]; i ...

  7. Python 自带IDLE 如何打开

  8. jquery 添加列

    {field:'action',title:'操作',width:70,align:'center',  formatter:function(value,row,index){  if (row.e ...

  9. Apache配置WSGI

    Apache配置WSGI 什么是WSGI WSGI被称作web服务器网关接口,在笔者看来其实是基于CGI标准针对Python语言做了一些改进,其主要功能是规范了web 服务器与Pythonj应用程序之 ...

  10. session的三种超时设置

    1.      在web容器中设置(此处以tomcat为例) 在tomcat-5.0.28\conf\web.xml中设置,以下是tomcat 5.0中的默认配置: <!-- ========= ...