从Maven中央仓库下载所需的jar包,需要外网的支持如果公司不能上外网的话则不能从中央仓库下载所需jar包,公司网速慢的时候也会影响项目构建的速度。用户可以用nexus创建私有的maven仓库。
首先下载nexus,下载地址是http://www.sonatype.org/nexus/go,在此页面可以下载最新版本的Nexus,可以下载zip包也可以下载war包两种包的部署方式不一样。
一、安装:
1.修改
D:\nexus-2.9.0-bundle\nexus-2.9.0-04\bin\jsw\conf\wrapper.conf
# Set the JVM executable
# (modify this to absolute path if you need a Java that is not on the OS path)
wrapper.java.command=C:\Java\jdk1.7.0_67\bin\java
修改为本地jdk地址,建议jdk1.6以上版本。
2.配置nexus环境变量
NEXUS_HOME=D:\nexus-2.9.0-bundle\nexus-2.9.0-04\bin
3.启动nexus start
二、上传本地jar
1.访问http://10.1.132.117:8081/nexus
2.admin/admin123
3.上传jar
4.选择已经上传的jar,
<dependency>
<groupId>com.oracle</groupId>
<artifactId>oracle6_suntao</artifactId>
<version>12.0</version>
</dependency>
放入到项目的pom文件中
三、项目pom文件的配置
<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>org.railway.gataway</groupId>
<artifactId>gataway</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>gataway Maven Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>nexus</id>
<name>Team Nexus Repository</name>
<url>http://10.1.132.117:8081/nexus/content/groups/public</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>Team Nexus Repository</name>
<url>http://10.1.132.117:8081/nexus/content/groups/public</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
</dependencies>
</project>
四、setting文件的配置
<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://localhost:8010/nexus/content/groups/public/</url>
</mirror>
</mirrors>
以下不配置,也能成功从私服下载jar到本地仓库,可能是去中央仓库下载jar
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>