maven + oschina镜像

1、maven 

       http://maven.apache.org/

2、新建环境变量  M2_HOME  ,输入值为 Maven 的安装目录。
3、新建环境变量  M2  ,输入值为:  %M2_HOME%\bin  。
4、将 M2 环境变量加入  Path  的最后,如:  ;%M2%  ;。

5、打开cmd,输入 mvn -version 

6、修改Maven 的安装目录下的 conf 文件下有个  settings.xml  文件

<mirrors>
	<!-- mirror | Specifies a repository mirror site to use instead of a given 
		repository. The repository that | this mirror serves has an ID that matches 
		the mirrorOf element of this mirror. IDs are used | for inheritance and direct 
		lookup purposes, and must be unique across the set of mirrors. | -->
	<mirror>
		<id>nexus-osc</id>
		<mirrorOf>*</mirrorOf>
		<name>Nexus osc</name>
		<url>http://maven.oschina.net/content/groups/public/</url>
	</mirror>
</mirrors>

7、如果还需要osc的thirdparty仓库或多个仓库,需要如下修改

<mirrors>
	<!-- mirror | Specifies a repository mirror site to use instead of a given 
		repository. The repository that | this mirror serves has an ID that matches 
		the mirrorOf element of this mirror. IDs are used | for inheritance and direct 
		lookup purposes, and must be unique across the set of mirrors. | -->
	<mirror>
		<id>nexus-osc</id>
		<mirrorOf>central</mirrorOf>
		<name>Nexus osc</name>
		<url>http://maven.oschina.net/content/groups/public/</url>
	</mirror>
	<mirror>
		<id>nexus-osc-thirdparty</id>
		<mirrorOf>thirdparty</mirrorOf>
		<name>Nexus osc thirdparty</name>
		<url>http://maven.oschina.net/content/repositories/thirdparty/</url>
	</mirror>
</mirrors>

8、在setting.xml里面,上面是配置 Maven 的 mirror 地址指向OSChina 的 Maven 镜像地址。 在执行 Maven 命令的时候, Maven 还需要安装一些插件包,这些插件包的下载地址也让其指向 OSChina 的 Maven 地址。

<profile>
    <id>jdk-1.4</id>
    <activation>
          <jdk>1.4</jdk>
    </activation>
    <repositories>
        <repository>
            <id>nexus</id>
            <name>local private nexus</name>
            <url>http://maven.oschina.net/content/groups/public/</url>
            <releases>
            	<enabled>true</enabled>
            </releases>
            <snapshots>
            	<enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <name>local private nexus</name>
            <url>http://maven.oschina.net/content/groups/public/</url>
            <releases>
            	<enabled>true</enabled>
            </releases>
            <snapshots>
            	<enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</profile>


9、在 settings.xml里面,如果您需要修改 Maven 的默认文件保存路径,需要在 settings.xml 文件中修改如下地方

<localRepository>D:/sw/server/Maven/Repo/m2</localRepository>


10、如果需要运行 jetty:run命令,则需要配置pluginGroups

<pluginGroups>  
    <pluginGroup>org.mortbay.jetty</pluginGroup>  
</pluginGroups>


11、创建maven项目

1)打开cmd
2) cd 【项目目录】
3)执行以下命令 mvn archetype:create -DgroupId=mygroupid -DartifactId=mytest -DpackageName=com.mygroupid.mytest  -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
    -DarchetypeArtifactId=maven-archetype-webapp   代表创建一个简单的 webapp 项目

4)添加包依赖
   Maven 也需要通过 xml 来配置。在项目的根目录下有一个  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>mygroupid</groupId>
    <artifactId>mygroupid.mytest</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
    <name>mygroupid.mytest Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>mygroupid.mytest</finalName>
    </build>
</project>


5)将项目安装到本地 repository
   A. CD 项目目录
   B.输入命令:mvn clean & mvn install



12、Eclipse 安装maven插件

1)点击Help->Install New Software
2)点击add,然后在Location中输入以下地址, http://download.eclipse.org/technology/m2e/releases 
3)重启后点击Window->Preferences可以看见maven的选项在左边导航栏出现,安装成功
4)配置m2eclipse插件,m2eclipse插件使用的是内置的Maven,为了保持一致性,需要将内置的Maven替换为我们自己安装的Maven,通过以下步骤进行配置
      A. 点击Window->Preferences
      B. 在左边的面板依次打开Maven->installations->add,然后填入你Maven所在的目录
      C. 点击finish,然后勾选我们刚才创建的选项,再点击OK,则完成配置

5)为插件选取已经设置代理的settings.xml (Window->Preferences-Maven->User Settings)








  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值