玩maven已经有多年了,但是一直没玩的很精通,最近自己从头开始学习各项参数的作用,今天把它贴出来,主要是两部分
1.maven公共仓库
http://mirrors.ibiblio.org/pub/mirrors/maven2/
http://gradle.artifactoryonline.com/gradle/libs
http://gradle.artifactoryonline.com/gradle/plugins
http://google-maven-repository.googlecode.com/svn/repository
http://maven.springframework.org/release
http://maven.springframework.org/milestone
http://repository.codehaus.org
http://repository.jboss.org/nexus/content/groups/public-jboss
http://repo.jfrog.org/artifactory/plugins-releases-local
http://repo.jfrog.org/artifactory/libs-releases-local
http://download.java.net/maven/1
http://download.java.net/maven/2
http://repo1.maven.org/maven2
http://www.intalio.org/public/maven2/
http://www.jarvana.com/jarvana/browse/
http://maven.alfresco.com/nexus/content/groups/public
上面加粗的那个是我现在用的公共仓库,为了便于不会配置的朋友便于应用,我把我的maven(版本3.0.5)的配置xml文件也贴出来
<settings>
<localRepository>W:\var\repository</localRepository>
<mirrors>
<mirror>
<id>CN</id>
<name>OSChina Central</name>
<url>http://repo1.maven.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
国内不需要代理也可正常使用,上面的
localRepository是本地仓库的配置地址,配置成自己的即可。
2.maven jar包导入方法
很多人在用maven的时候不知道jar包的groupId和artifactId无法下手,其实很简单,需要分为以下两部即可轻松通过maven导入jar包
(1)去http://search.maven.org/查询通过jar包的模糊名称查询jar包的groupId和artifactId。如下图
我搜索“spring-webmvc”即可查询到相关的jar包,然后找到合适的版本,复制它的groupId和artifactId即可。
(2)在pom.xml进行添加如下代码
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
然后点击保存,maven就会自动下载该版本的spring web-mvc相关的jar包了。
最后我贴出一个我经过测试,结合了jetty服务的一个pom.xml,有需要的朋友们可以参考一下
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bjfulei</groupId>
<artifactId>SpringHello</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>SpringHello Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<spring.version>4.1.4.RELEASE</spring.version>
<jdk.version>1.7</jdk.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.7</version>
</dependency>
<dependency>
<groupId>org.darkphoenixs</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>
<finalName>SpringHello</finalName>
<plugins>
<!-- compiler插件, 设定JDK版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.10.v20150310</version>
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
<webApp>
<contextPath>/SpringHello</contextPath>
</webApp>
</configuration>
</plugin>
</plugins>
<defaultGoal>compile</defaultGoal>
</build>
</project>