maven安装与使用

3 篇文章 0 订阅

买了一本《maven实战》还不错的。买了很久,最近又要开始做java项目回顾一下,还是记录下来省的翻书麻烦的。

一、下载与安装

       1、 前提已安装jdk并配置JAVA_HOME因为maven需要运行java命令。

       2、apache网站maven下载目前apache-maven-3.0.5-bin.zip  ,解压到任意目录 。添加bin批处理命令目录到环境变量path中。F:\JavaDecompress\apache-maven-3.0.5\

       3、同样下载nexus一个maven仓库管理器目前版本nexus-2.3.1-01。jsw包下有各种环境的批处理命令,运行console-nexus.bat访问:http://localhost:8081/nexus 用户admin密码admin123。这里只需要把central的download索引 修改为true就可以了。如果启动nexus的时候报java.lang.UnsupportedClassVersionError: Bad version number in .class file,原因是nexus需要的java_home指定的jdk版本不匹配,可以指定jdk路径,在\bin\jsw\conf\warpper.config配置文件中设置wrapper.java.command=D:\Program Files\Java\jdk1.6.0_10\bin\JAVA (如果已配置环境变量,可以直接=java)    就可以正常启动neuxus服务器了

二、安装eclipse 的maven插件  

       1、下载eclipse,目前使用eclipse4.2 安装maven插件,貌似以前的maven插件地址已经转向了eclipse官方插件了。
       2、在eclipse marketplace中安装 Maven Integration for Eclipse(m2e)
       3、可以选择安装Maven Integration for Eclipse WTP (m2e-wtp)这个是用来把以前的java项目转为maven项目用的?
       4、修改eclipse配置maven的路径一个是全局配置路径一个用户配置路径


三、配置maven和nexus

       修改apache-maven-3.0.5\conf下的setting.xml文件配置主要改下仓库存放路径,使用私服nexus来代理中央仓库。配置文件一定要写对不然默认会从中央仓库下载索引或者下不了jar包
<?xml version="1.0" encoding="UTF-8"?>


<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ~/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <localRepository>F:\SvnProject\SampleProjects\JavaProjectDemo\MavenRepository</localRepository>
  <pluginGroups>
  </pluginGroups>
  <proxies>
  </proxies>
  <servers>
  </servers>
  <mirrors>
     <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://192.168.1.131:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>central</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://central</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
          <releases>
        	<enabled>true</enabled>
      	  </releases>
      	  <snapshots>
        	<enabled>true</enabled>
      	  </snapshots>
        </repository>
      </repositories>
    <pluginRepositories>  
     <pluginRepository>  
       <id>nexus</id>  
       <name>Central Repository</name>  
       <url>http://central</url>  
       <layout>default</layout>  
       <snapshots>  
        <enabled>true</enabled>  
       </snapshots>  
       <releases>  
        <enabled>true</enabled>  
       </releases>  
      </pluginRepository>  
     </pluginRepositories> 
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

四、创建eclipse maven项目

      1、新建项目的时候可能想要创建的项目骨架原型没有这个可以自己建一个Maven里面配置一下就有了6万多个。。。。

五、问题

       1、使用maven的过程中会遇到一些错误,比如找不到包,下载不了。可能是因为maven限制ip下载数量导致索引下载不下来,或者是只有pom文件没有jar这个时候最好选择低版本的,不要盲目使用高版本的jar。因为即使maven仓库没有你要的包,它仍然会试着下载导致maven 本地repository 还能有后缀为lastupdate的文件。把这个删除重新下低版本的。
       2、maven 执行install命令的时候 编译失败
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project MyProject: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] C:\Development\java jre7\..\lib\tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and
[ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.
这个原因可能是maven 编译需要用到jdk  里面的jar。jre下面没有,解决办法为

It has 4 steps TODO.

Step 1 : Right Click on Eclipse project Properties

Step 2 : Java Build Path >Libraries

Step 3 : Click on JRE > Edit > Installed JRE

Step 4 : Edit Jre > Set JRE Home = JAVA_HOME

还有一个原因是你装了多个 jre 。系统不知道用哪一个。这个时候可以设置一下或者删除一个只用一个







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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值