maven打包资源文件(转)
原文链接: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打包资源文件(转)的更多相关文章
- Maven 包含资源文件
Maven打包时,如何包含资源文件(src/main/java | src/main/resources): 参考博客:http://blog.csdn.net/jsflzhong/article/d ...
- Pyqt 打包资源文件
用打包工具将做好的Pyqt程序打包成exe后发现引用的资源图片都显示不了? 是否遇到了和我一样的问题呢.google之后找到了方法,一种方法是在程序中引用外部资源,另外一种方法是将资源文件转换为py文 ...
- VS打包资源文件,转自推酷,请小星同学查看
上篇博客把收费系统的总体设计进行了一遍讲解,讲解的同时掺杂了些有关.NET编译机制的总结.程序编写测试完成后接下来我们要做的是打包部署程序,但VS2012让人心痛的是没有了打包工具.不知道出于什么原因 ...
- Webpack 使用url-loader和file-loader打包资源文件
在js中不仅可以通过import引入js文件,还可以引入图片.视频等资源文件,这样webpack打包时就会把所引入的资源文件也一起打包进来 打包进来的文件会返回一个字符串:即文件的路径 要做到这一点, ...
- pyinstall打包资源文件
相关代码 main.py import sys import os #生成资源文件目录访问路径 #说明: pyinstaller工具打包的可执行文件,运行时sys.frozen会被设置成True # ...
- 记一次maven打包编译文件一直不正确
maven打包发现war包解压后的class文件总是跟原Java不一样 后来发现pom中这么写到 <plugins> <plugin> <artifactId>ma ...
- maven 打包 xml文件
说起来手贱啊,搞了两个小时,就是因为打包的时候,maven无法把xml文件打包到正确的位置. 本来应该是打包到 com/presistence包下,结果打出来有两个包,一个是com/presisten ...
- Maven让资源文件处理插件能够解析资源文件中的Maven属性
<build> <resources> <resource> <directory>${project.basedir}/src/main/resour ...
- Maven编译资源文件拷贝
<build> <finalName>op-balance-job-service</finalName> <plugins> <plugin&g ...
随机推荐
- mysql 约束条件 unique key 唯一的键
如果不设置unique 会出现两条相同的记录 mysql)); Query OK, rows affected (0.01 sec) mysql ,,'mike'); Query OK, rows a ...
- 3.mysql自增的字段如何重新派逊
alter table sales drop id;ALter table sales add id int(6) PRIMARY key not null auto_increment FIRST;
- [golang note] 网络编程 - RPC编程
net包 • 官方文档 http://godoc.golangtc.com/pkg/net/ Package net provides a portable interface for network ...
- 解决升级到Xcode10,react native项目运行报错问题
今天刚升级到Xcode10,就遇到两个报错问题 错误一:Xcode 10: Build input file double-conversion cannot be found error: Buil ...
- node必知必会之node简介
1.什么是node.js 按照: Node.js官方网站主页 的说法: Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript ...
- VS2010/MFC编程入门之二十一(常用控件:编辑框Edit Control)
鸡啄米上一节讲了静态文本框,本节要讲的编辑框(Edit Control)同样是一种很常用的控件,我们可以在编辑框中输入并编辑文本.在前面加法计算器的例子中已经演示了编辑框的基本应用.下面具体讲解编辑框 ...
- ng-深度学习-课程笔记-12: 深度卷积网络的实例探究(Week2)
1 实例探究( Cast Study ) 这一周,ng对几个关于计算机视觉的经典网络进行实例分析,LeNet-5,AlexNet,VGG,ResNet,Inception. 2 经典网络( Class ...
- myeclipse安装jadclipse(反编译工具)
我是myeclipse5. 的IDE工具.为了能反编译class文件,上网搜索了很多资料,终于找到一下的一段资料: .将jad.exe 复制到myeclipse安装目录的jre/bin目录下, 如:C ...
- c++第二十四天
p126~p128: 1.关系运算符作用于算数类型和指针类型. 2.逻辑运算符作用于任意能转换成布尔类型值的类型. 3.以上两种运算的运算对象和运算结果都是右值. 4.逻辑与和逻辑或的运算策略:短路求 ...
- 基于ORB的LinearBlend融合
// L14//基于ORB实现线性融合#include "stdafx.h"#include <vector>#include <opencv2/core.hpp ...