刚刚把项目从Ant转到Maven,费了好多劲,主要是对Maven边用边学。问题主要集中在项目结构上不太一样,在程序的访问上也有区别,调试和打包等也和原来不太一样。终于折腾完一个可以正常运行的POM配置,记录一下,将遇到的问题也注释在了配置中,便于查阅。

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.garfield.gserver</groupId>
  5. <artifactId>GServer</artifactId>
  6. <version>0.0.1-SNAPSHOT</version>
  7.  
  8. <dependencies>
  9.  
  10. <dependency>
  11. <groupId>org.apache.logging.log4j</groupId>
  12. <artifactId>log4j-api</artifactId>
  13. <version>2.0-beta9</version>
  14. </dependency>
  15.  
  16. <!--
  17. ERROR Root contains an invalid element or attribute "AppenderRef"
  18. This is an error for 2.0-beta8, it is not present on 2.0-beta9
  19. -->
  20.  
  21. <dependency>
  22. <groupId>org.apache.logging.log4j</groupId>
  23. <artifactId>log4j-core</artifactId>
  24. <version>2.0-beta9</version>
  25. </dependency>
  26.  
  27. <dependency>
  28. <groupId>org.slf4j</groupId>
  29. <artifactId>slf4j-api</artifactId>
  30. <version>1.7.7</version>
  31. </dependency>
  32.  
  33. <dependency>
  34. <groupId>org.apache.logging.log4j</groupId>
  35. <artifactId>log4j-jcl</artifactId>
  36. <version>2.0-rc1</version>
  37. </dependency>
  38.  
  39. <dependency>
  40. <groupId>org.apache.logging.log4j</groupId>
  41. <artifactId>log4j-slf4j-impl</artifactId>
  42. <version>2.0-rc1</version>
  43. </dependency>
  44.  
  45. <dependency>
  46. <groupId>org.apache.commons</groupId>
  47. <artifactId>commons-lang3</artifactId>
  48. <version>3.1</version>
  49. </dependency>
  50.  
  51. <dependency>
  52. <groupId>org.hibernate</groupId>
  53. <artifactId>hibernate-core</artifactId>
  54. <version>4.3.5.Final</version>
  55. </dependency>
  56.  
  57. <dependency>
  58. <groupId>org.springframework</groupId>
  59. <artifactId>spring-orm</artifactId>
  60. <version>4.0.3.RELEASE</version>
  61. </dependency>
  62.  
  63. <dependency>
  64. <groupId>org.springframework</groupId>
  65. <artifactId>spring-context</artifactId>
  66. <version>4.0.3.RELEASE</version>
  67.  
  68. </dependency>
  69.  
  70. <dependency>
  71. <groupId>org.springframework</groupId>
  72. <artifactId>spring-core</artifactId>
  73. <version>4.0.3.RELEASE</version>
  74. </dependency>
  75.  
  76. <dependency>
  77. <groupId>org.springframework</groupId>
  78. <artifactId>spring-beans</artifactId>
  79. <version>4.0.3.RELEASE</version>
  80. </dependency>
  81.  
  82. <dependency>
  83. <groupId>org.springframework</groupId>
  84. <artifactId>spring-tx</artifactId>
  85. <version>4.0.3.RELEASE</version>
  86. </dependency>
  87.  
  88. <dependency>
  89. <groupId>org.springframework</groupId>
  90. <artifactId>spring-tx</artifactId>
  91. <version>4.0.3.RELEASE</version>
  92. </dependency>
  93.  
  94. <dependency>
  95. <groupId>org.springframework</groupId>
  96. <artifactId>spring-jdbc</artifactId>
  97. <version>4.0.3.RELEASE</version>
  98. </dependency>
  99.  
  100. <!-- json-lib是需要区分jdk版本的,pom.xml中的配置应加上<classifier>标签,如用jdk15: -->
  101. <dependency>
  102. <groupId>net.sf.json-lib</groupId>
  103. <artifactId>json-lib</artifactId>
  104. <version>2.4</version>
  105. <classifier>jdk15</classifier>
  106. </dependency>
  107.  
  108. <dependency>
  109. <groupId>junit</groupId>
  110. <artifactId>junit</artifactId>
  111. <version>4.11</version>
  112. </dependency>
  113.  
  114. <dependency>
  115. <groupId>com.microsoft.sqlserver</groupId>
  116. <artifactId>sqljdbc4</artifactId>
  117. <version>4.0</version>
  118. </dependency>
  119.  
  120. <dependency>
  121. <groupId>com.mchange</groupId>
  122. <artifactId>c3p0</artifactId>
  123. <version>0.9.5-pre8</version>
  124. </dependency>
  125.  
  126. <dependency>
  127. <groupId>commons-codec</groupId>
  128. <artifactId>commons-codec</artifactId>
  129. <version>1.9</version>
  130. </dependency>
  131.  
  132. <!-- maven打包编译的异常 :sun.misc.BASE64Decoder 是 Sun 的专用 API,可能会在未来版本中删除的解决方法 -->
  133. <dependency>
  134. <groupId>org.codehaus.plexus</groupId>
  135. <artifactId>plexus-compiler-javac</artifactId>
  136. <version>1.8.1</version>
  137. </dependency>
  138.  
  139. <!-- maven工程 仓库没有的jar使用方法 <dependency> <groupId>cryptix</groupId> <artifactId>cryptix-jce-api</artifactId>
  140. <version>1.0</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/cryptix-jce-api.jar</systemPath>
  141. </dependency> -->
  142.  
  143. <!-- <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId>
  144. <version>2.0-rc1</version> </dependency> -->
  145.  
  146. </dependencies>
  147.  
  148. <properties>
  149. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  150. </properties>
  151.  
  152. <build>
  153. <defaultGoal>compile</defaultGoal>
  154.  
  155. <plugins>
  156. <plugin>
  157. <groupId>org.apache.maven.plugins</groupId>
  158. <artifactId>maven-compiler-plugin</artifactId>
  159. <version>3.1</version>
  160. <configuration>
  161. <source>1.7</source>
  162. <target>1.7</target>
  163. <encoding>UTF-8</encoding> <!-- “编码 GBK 的不可映射字符”问题的解决 -->
  164. </configuration>
  165. </plugin>
  166.  
  167. <plugin>
  168. <groupId>org.apache.maven.plugins</groupId>
  169. <artifactId>maven-surefire-plugin</artifactId>
  170. <configuration>
  171. <includes>
  172. <!--不写匹配默认规则,TestSuit结尾,test开头的方法 -->
  173. <include>**/*TestSuit.java</include> <!-- 两个星号**用来匹配任意路径,一个星号*用来获取除路径风格符外的0个或多个字符 -->
  174. </includes>
  175. <excludes>
  176. <exclude>**/CollectionBillTestCase.java</exclude>
  177. <exclude>**/PaymentBillTestCase.java</exclude>
  178. </excludes>
  179. <skip>false</skip> <!-- 略过单元测试 -->
  180. <testFailureIgnore>true</testFailureIgnore> <!-- 当Maven 遇到一个测试失败,它默认的行为是停止当前的构建。 如果你希望继续构建项目,即使 Surefire 插件遇到了失败的单元测试,你就需要设置 Surefire 的testFailureIgnore 这个配置属性为 true -->
  181. </configuration>
  182. </plugin>
  183.  
  184. <!-- 把依赖的jar包拷到lib目录下 -->
  185.  
  186. <plugin>
  187. <groupId>org.apache.maven.plugins</groupId>
  188. <artifactId>maven-dependency-plugin</artifactId>
  189. <executions>
  190. <execution>
  191. <id>copy-dependencies</id>
  192. <phase>package</phase>
  193. <goals>
  194. <goal>copy-dependencies</goal>
  195. </goals>
  196. <configuration>
  197. <outputDirectory>${project.build.directory}/lib</outputDirectory>
  198. <overWriteReleases>false</overWriteReleases>
  199. <overWriteSnapshots>false</overWriteSnapshots>
  200. <overWriteIfNewer>true</overWriteIfNewer>
  201. </configuration>
  202. </execution>
  203. </executions>
  204. </plugin>
  205.  
  206. <!-- 把配置文件拷到和jar包同一个路径下 -->
  207. <!-- 以utf-8编码拷贝配置文件,拷贝过程中是可以做变量替换的,也就是说你的配置文件可以是个模板,里面的${}所包含的内容是可以拷贝过程中替换的 -->
  208. <!--
  209. <plugin>
  210. <groupId>org.apache.maven.plugins</groupId>
  211. <artifactId>maven-resources-plugin</artifactId>
  212. <version>2.4</version>
  213. <executions>
  214. <execution>
  215. <id>copy-resources</id>
  216. <phase>package</phase>
  217. <goals>
  218. <goal>copy-resources</goal>
  219. </goals>
  220. <configuration>
  221. <encoding>UTF-8</encoding>
  222. <outputDirectory>${project.build.directory}</outputDirectory>
  223. <resources>
  224. <resource>
  225. <directory>src/main/resources/</directory>
  226. <filtering>true</filtering>
  227. </resource>
  228. </resources>
  229. </configuration>
  230. </execution>
  231. </executions>
  232. </plugin>
  233. -->
  234. <!-- 打jar包时需要把配置文件给排除在外 -->
  235. <!--
  236. <plugin>
  237. <groupId>org.apache.maven.plugins</groupId>
  238. <artifactId>maven-jar-plugin</artifactId>
  239. <version>2.4</version>
  240. <executions>
  241. <execution>
  242. <phase>package</phase>
  243. <goals>
  244. <goal>jar</goal>
  245. </goals>
  246. <configuration>
  247. <archive>
  248. <manifest>
  249. <addClasspath>true</addClasspath>
  250. <classpathPrefix>lib/</classpathPrefix>
  251. <mainClass>com.garfield.gui.Main</mainClass>
  252. </manifest>
  253. </archive>
  254. <classifier>lib</classifier>
  255. </configuration>
  256. </execution>
  257. </executions>
  258. </plugin>
  259. -->
  260. <plugin>
  261. <groupId>org.apache.maven.plugins</groupId>
  262. <artifactId>maven-jar-plugin</artifactId>
  263. <version>2.4</version>
  264. <configuration>
  265. <archive>
  266. <manifest>
  267. <addClasspath>true</addClasspath> <!-- 在jar包中增加依赖jar路径说明 -->
  268. <classpathPrefix>lib/</classpathPrefix>
  269. <mainClass>com.garfield.gui.Main</mainClass>
  270. </manifest>
  271.  
  272. <!-- 用maven在MANIFEST.MF资料中的Class-Path中增加当前目录(.) -->
  273. <manifestEntries>
  274. <Class-Path>.</Class-Path>
  275. </manifestEntries>
  276.  
  277. </archive>
  278. </configuration>
  279. </plugin>
  280.  
  281. <!--
  282. <plugin>
  283. <groupId>org.apache.maven.plugins</groupId>
  284. <artifactId>maven-assembly-plugin</artifactId>
  285. <version>2.2</version>
  286. <configuration>
  287. <descriptors>
  288. <descriptor>/assembly.xml</descriptor>
  289. </descriptors>
  290. </configuration>
  291. <executions>
  292. <execution>
  293. <id>make-assembly</id>
  294. <phase>package</phase>
  295. <goals>
  296. <goal>single</goal>
  297. </goals>
  298. </execution>
  299. </executions>
  300. </plugin>
  301. -->
  302. </plugins>
  303.  
  304. <!-- POM文件报错maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e.,
  305. 在</build>标签前添加如下内容 -->
  306.  
  307. <pluginManagement>
  308. <plugins>
  309. <plugin>
  310. <groupId>org.eclipse.m2e</groupId>
  311. <artifactId>lifecycle-mapping</artifactId>
  312. <version>1.0.0</version>
  313. <configuration>
  314. <lifecycleMappingMetadata>
  315. <pluginExecutions>
  316. <pluginExecution>
  317. <pluginExecutionFilter>
  318. <groupId>org.apache.maven.plugins</groupId>
  319. <artifactId>maven-dependency-plugin</artifactId>
  320. <versionRange>[2.0,)</versionRange>
  321. <goals>
  322. <goal>copy-dependencies</goal>
  323. <goal>unpack</goal>
  324. </goals>
  325. </pluginExecutionFilter>
  326. <action>
  327. <ignore />
  328. </action>
  329. </pluginExecution>
  330. </pluginExecutions>
  331. </lifecycleMappingMetadata>
  332. </configuration>
  333. </plugin>
  334. </plugins>
  335. </pluginManagement>
  336.  
  337. <resources>
  338. <!--打包进XML等文件,排除java及版本控制文件 -->
  339. <resource>
  340. <directory>src/main/java</directory>
  341. <excludes>
  342. <exclude>**/*.java</exclude>
  343. <exclude>**/.svn/*</exclude>
  344. </excludes>
  345. </resource>
  346. <resource>
  347. <directory>src/main/resources</directory>
  348. <includes>
  349. <include>**/*.*</include>
  350. <include>**/*.*</include>
  351. </includes>
  352. </resource>
  353. </resources>
  354. </build>
  355.  
  356. </project>
  1. 如果使用assembly编译,则用到下面的assembly.xml:
  1. <assembly>
  2. <id>bin</id>
  3. <formats>
  4. <format>zip</format>
  5. </formats>
  6.  
  7. <includeBaseDirectory>true</includeBaseDirectory>
  8.  
  9. <dependencySets>
  10. <dependencySet>
  11. <outputDirectory>lib</outputDirectory>
  12. <scope>runtime</scope>
  13. </dependencySet>
  14. </dependencySets>
  15.  
  16. <fileSets>
  17. <fileSet>
  18. <outputDirectory>/</outputDirectory>
  19. <includes>
  20. <include>README.txt</include>
  21. </includes>
  22. </fileSet>
  23. <fileSet>
  24. <directory>src/main/java</directory>
  25. <outputDirectory>/</outputDirectory>
  26. <includes>
  27. <include>hibernate.cfg.xml</include>
  28. <include>jserver.properties</include>
  29. <include>log4j.properties</include>
  30. <include>log4j2.xml</include>
  31. </includes>
  32. </fileSet>
  33. </fileSets>
  34. </assembly>

我的Maven POM配置的更多相关文章

  1. Maven POM配置释疑

    1.  对于有父子关系的Project, 父POM中依赖使用dependencies 和 dependencyManagement 的区别: dependencies: 即使子项目中不写该依赖项,仍然 ...

  2. Maven pom配置(Spring+SpringMvc+mybaties)

    <?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven ...

  3. Maven pom 配置简介

    1. groupId artifactId version 2. dependencies 3. plugins http://shmilyaw-hotmail-com.iteye.com/blog/ ...

  4. Maven pom.xml 配置说明: 打jar包不包括指定资源文件和.class xml,配置不跑testCase,建pom父子项目

    **maven如何配置打jar包时,一些class 或者资源文件不打进来,把classpath的xml文件打进jar <build> <!--针对资源文件--> <res ...

  5. maven打包 tomcat运行pom配置 或 打成jar包

    maven打包 tomcat运行pom配置,同时还需要配置org.apache.tomcat.maven插件,这里省略. <groupId>com.company</groupId& ...

  6. maven 仓库配置 pom中repositories属性

    文章转自http://blog.csdn.net/zlgydx/article/details/51130627 什么是Maven仓库在不用Maven的时候,比如说以前我们用Ant构建项目,在项目目录 ...

  7. (转)Maven pom.xml 配置详解

    背景:maven一直感觉既熟悉又陌生,归根结底还是自己不太熟. 1 什么是pom? pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者 ...

  8. maven pom文件简单模板和配置详解

    https://blog.csdn.net/earbao/article/details/49924943 maven pom文件简单模板和配置详解

  9. Maven(四-2) Maven pom.xml 配置详解

    转载于:http://niuzhenxin.iteye.com/blog/2042102 什么是pom?    pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述 ...

随机推荐

  1. 最小二乘法多项式曲线拟合原理与实现 zz

    概念 最小二乘法多项式曲线拟合,根据给定的m个点,并不要求这条曲线精确地经过这些点,而是曲线y=f(x)的近似曲线y= φ(x). 原理 [原理部分由个人根据互联网上的资料进行总结,希望对大家能有用] ...

  2. MFC中onmouseover与onmousemove的区别

    onmouseover与onmousemove的区别是:当鼠标移过当前对象时就产生了onmouseover事件,当鼠标在当前对象上移动时就产生了onmousemove事件,只要是在对象上移动而且没有移 ...

  3. 大数据开发实战:Hadoop数据仓库开发实战

    1.Hadoop数据仓库架构设计 如上图. ODS(Operation Data Store)层:ODS层通常也被称为准备区(Staging area),它们是后续数据仓库层(即基于Kimball维度 ...

  4. 中文分词 coreseek安装笔记

    #!/bin/bash # create by lhb # date 2013-11-26 # coreseek install script apt-get install make gcc g++ ...

  5. 论文列表——text classification

    https://blog.csdn.net/BitCs_zt/article/details/82938086 列出自己阅读的text classification论文的列表,以后有时间再整理相应的笔 ...

  6. 使用tensorflow的lstm网络进行时间序列预测

    https://blog.csdn.net/flying_sfeng/article/details/78852816 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog. ...

  7. .NET 常用加密、解密& 数字签名算法

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Run ...

  8. 解决PHP使用CVS导出Excel乱码问题

    在使用PHP生成CVS文件后通过Excel打开发现中文全部变成了乱码,之前在我本地win08通过WPS正常的,但上传到服务器Linux在服务器上测试出现了乱码 一开始以后是Linux的问题但后来测试时 ...

  9. 解决ThinkPHP的Create方法失效而没有提示错误信息的问题

    ThinkPHP中的数据创建Create方法是一个非常有用的功能,它自动根据表单数据创建数据对象(在表字段很多的情况下尤其明显) 但有时候该方法可能并未按照你期望的来工作,比如方法不工作而且还没有提示 ...

  10. servlet种下cookie后如何携带cookie继续往下走

    事情是这样的,今天我在应用1里面手动种下了一个cookie,然后它会发接着访问应用2,因为是我手动setCookie,所以它还没来得及携带cookie继续前往下一站,于是,apple pen,炸了. ...