非标准maven工程的resource资源提交

来源:互联网 发布:linux创建文件夹进入 编辑:程序博客网 时间:2024/06/05 11:50
标准的Maven工程,目录结构如下,资源都是放在"src/main/resources"下的,所以在打包成jar的时候无须特别处理。

src/main/java

Application/Library sources

src/main/resources

Application/Library resources

src/main/filters

Resource filter files

src/main/config

Configuration files

src/main/scripts

Application/Library scripts

src/main/webapp

Web application sources

src/test/java

Test sources

src/test/resources

Test resources

src/test/filters

Test resource filter files

src/it

Integration Tests (primarily for plugins)

src/assembly

Assembly descriptors

src/site

Site

LICENSE.txt

Project's license

NOTICE.txt

Notices and attributions required by libraries that the project depends on

README.txt

Project's readme

(来源:http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html)


但是在eclipse中,如果是把原来的java工程conver成maven工程,目录结构还是标准的java工程,只是增加了一个pom.xml而已,所以这种情况下如果涉及到resource资源的打包及使用的话,需要做如下两步:

1、 pom.xml的<build>下增加resource说明

resources(通常)不是代码,他们不被编译,但是被绑定在你的项目或者用于其它什么原因,例如代码生成。

[html] view plaincopy
  1. <build>  
  2.     ...  
  3.     <resources>  
  4.          <resource>  
  5.             <targetPath>META-INF/plexus</targetPath>  
  6.             <filtering>false</filtering>  
  7.             <directory>${basedir}/src/main/plexus</directory>  
  8.             <includes>  
  9.                 <include>configuration.xml</include>  
  10.             </includes>  
  11.             <excludes>  
  12.                 <exclude>**/*.properties</exclude>  
  13.             </excludes>  
  14.          </resource>  
  15.     </resources>  
  16.     <testResources>  
  17.         ...  
  18.     </testResources>  
  19.     ...  
  20. </build>  
1、resources:一个resource元素的列表,每一个都描述与项目关联的文件是什么和在哪里;
2、targetPath:指定build后的resource存放的文件夹。该路径默认是basedir。通常被打包在JAR中的resources的目标路径为META-INF;
3、filtering:true/false,表示为这个resource,filter是否激活。
4、directory:定义resource所在的文件夹,默认为${basedir}/src/main/resources;
5、includes:指定作为resource的文件的匹配模式,用*作为通配符;
6、excludes:指定哪些文件被忽略,如果一个文件同时符合includes和excludes,则excludes生效;
7、testResources:定义和resource类似,但只在test时使用,默认的test resource文件夹路径是${basedir}/src/test/resources,test resource不被部署(来源:http://blog.csdn.net/tomato__/article/details/13625497)


2、 更新maven工程

工程右键-Maven-Update Project

0 0