Maven基本配置

Mar 8, 2018 4:21:51 PM

作者:wendal

Nutz核心jar

nutz及周边插件,均已发布到maven中央库库,可以直接配置使用

  1. <dependency>
  2. <groupId>org.nutz</groupId>
  3. <artifactId>nutz</artifactId>
  4. <version>1.r.65</version>
  5. </dependency>

快照库地址 https://jfrog.nutz.cn/artifactory/snapshots

快照库内包含nutz主库,插件库,等快照jar

常用配置模板

新建项目的参考配置,nutz+mysql+druid,并应用了nutzcn提供的maven镜像服务及快照库.

  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>mygroupId</groupId>
  5. <artifactId>myartifactId</artifactId>
  6. <packaging>war</packaging>
  7. <version>1.0-SNAPSHOT</version>
  8. <properties>
  9. <!-- UTF8大法好 -->
  10. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  11. </properties>
  12. <dependencies>
  13. <!-- 核心jar -->
  14. <dependency>
  15. <groupId>org.nutz</groupId>
  16. <artifactId>nutz</artifactId>
  17. <version>1.r.65</version>
  18. </dependency>
  19. <!-- mysql驱动 -->
  20. <dependency>
  21. <groupId>mysql</groupId>
  22. <artifactId>mysql-connector-java</artifactId>
  23. <version>5.1.44</version>
  24. </dependency>
  25. <dependency>
  26. <groupId>javax.servlet</groupId>
  27. <artifactId>javax.servlet-api</artifactId>
  28. <version>3.1.0</version>
  29. <scope>provided</scope>
  30. </dependency>
  31. <!-- Druid连接池 -->
  32. <dependency>
  33. <groupId>com.alibaba</groupId>
  34. <artifactId>druid</artifactId>
  35. <version>1.1.5</version>
  36. </dependency>
  37. <dependency>
  38. <groupId>junit</groupId>
  39. <artifactId>junit</artifactId>
  40. <version>4.12</version>
  41. <scope>test</scope>
  42. </dependency>
  43. </dependencies>
  44. <build>
  45. <plugins>
  46. <plugin>
  47. <artifactId>maven-compiler-plugin</artifactId>
  48. <version>3.3</version>
  49. <configuration>
  50. <source>1.8</source>
  51. <target>1.8</target>
  52. <compilerArgs>
  53. <arg>-parameters</arg>
  54. </compilerArgs>
  55. <useIncrementalCompilation>false</useIncrementalCompilation>
  56. </configuration>
  57. </plugin>
  58. </plugins>
  59. </build>
  60. <repositories>
  61. <repository>
  62. <id>nutz</id>
  63. <url>http://jfrog.nutz.cn/artifactory/libs-release</url>
  64. <snapshots>
  65. <enabled>false</enabled>
  66. </snapshots>
  67. </repository>
  68. <repository>
  69. <id>nutz-snapshots</id>
  70. <url>http://jfrog.nutz.cn/artifactory/snapshots</url>
  71. <snapshots>
  72. <enabled>true</enabled>
  73. <updatePolicy>always</updatePolicy>
  74. </snapshots>
  75. <releases>
  76. <enabled>false</enabled>
  77. </releases>
  78. </repository>
  79. </repositories>
  80. </project>

特别提醒

如果配置过镜像库,例如阿里的镜像库, 你的settings.xml里面也许有这样的配置,注意星号

  1. <mirror>
  2. <id>nexus-aliyun</id>
  3. <mirrorOf>*</mirrorOf>
  4. <name>Nexus aliyun</name>
  5. <url>http://maven.aliyun.com/nexus/content/groups/public</url>
  6. </mirror>

这个配置是错误的, 星号代表全部,无论是release还是snapshots都代理, 会导致所有第三方快照库的设置都失效. 要改成

  1. <mirror>
  2. <id>nexus-aliyun</id>
  3. <mirrorOf>central</mirrorOf>
  4. <name>Nexus aliyun</name>
  5. <url>http://maven.aliyun.com/nexus/content/groups/public</url>
  6. </mirror>

本页面的文字允许在知识共享 署名-相同方式共享 3.0协议GNU自由文档许可证下修改和再使用。

原文: http://nutzam.com/core/basic/maven.html