---
title: "初学maven(1)-常见小问题集锦"
author: "skydream"
date: "2008-06-18T17:09:00Z"
tags: []
slug: "maven-1"
draft: false
lastmod: "2009-08-02T11:40:26Z"
id: 437956
url: "https://skydream.iteye.com/blog/437956"
---

初学maven，遇到不少问题，记录下来，呵呵，依然是备忘兼共享。

一. The pulgin 'org.apache.maven.plugins:maven-archetype-plugin ' does not exist or valid version could be found

    安装官方标准的安装方式（http://maven.apache.org/download.html#Installation）安装完毕，运行mvn --version没有问题。  
    然后按照"maven in 5 minutes"(http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html) 的第一个例子，执行

&lt;!--&lt;br /&gt; &lt;br /&gt; Code highlighting produced by Actipro CodeHighlighter (freeware)&lt;br /&gt; http://www.CodeHighlighter.com/&lt;br /&gt; &lt;br /&gt; --&gt;mvn archetype:create  - DgroupId = com.mycompany.app  - DartifactId = my - app

    结果报错：  
    The pulgin 'org.apache.maven.plugins:maven-archetype-plugin ' does not exist or valid version could be found  
    ......

    google了一下发现解决方案，原来是网络配置的问题，如果使用代理上网必须修改maven的配置文件加入相应的代理信息。  
    打开文件 maven/conf/settings.xml，找到&lt;proxies&gt;，将原来注释掉的&lt;proxy&gt;打开，修改相应的信息即可。  
    注意：  
    1.）&lt;host&gt;iproxy-sh.cn.ao.ericsson.se&lt;/host&gt; 这里不要用"http://"开头，否则会无法连接  
    2. ) 如果用户名、密码不需要，可以删除&lt;username&gt;&lt;password&gt;，设置为空也行。

二. artifactory私服安装问题  
    对于单机来说，maven从远程仓库取jar包等资源是完全合理的。但是如果一个team甚至一个公司，每个人的maven都从远程仓库取，那么花在文件下载上的时间就太多了，而且完全没有必要。因此设置一个开发团队共享的Maven2的私服就必不可少了。  
    Maven2的私服，当然首选artifactory。  
    跑到artifactory的官网，down下来最新的1.30-beta1，安装非常简单，windows下一个bat文件直接启动。之后修改maven配置，加入

&lt;!--&lt;br /&gt; &lt;br /&gt; Code highlighting produced by Actipro CodeHighlighter (freeware)&lt;br /&gt; http://www.CodeHighlighter.com/&lt;br /&gt; &lt;br /&gt; --&gt;  &lt; repositories &gt;     
      &lt; repository &gt;     
          &lt; id &gt; central &lt;/ id &gt;     
          &lt; url &gt; http: // localhost:8081/artifactory/repo&lt;/url&gt;    
          &lt; snapshots &gt;     
              &lt; enabled &gt; false &lt;/ enabled &gt;     
          &lt;/ snapshots &gt;     
      &lt;/ repository &gt;     
      &lt; repository &gt;     
          &lt; id &gt; snapshots &lt;/ id &gt;     
          &lt; url &gt; http: // localhost:8081/artifactory/repo&lt;/url&gt;    
          &lt; releases &gt;     
              &lt; enabled &gt; false &lt;/ enabled &gt;     
          &lt;/ releases &gt;     
      &lt;/ repository &gt;     
  &lt;/ repositories &gt;     
  &lt; pluginRepositories &gt;     
      &lt; pluginRepository &gt;     
          &lt; id &gt; central &lt;/ id &gt;     
          &lt; url &gt; http: // localhost:8081/artifactory/plugins-releases&lt;/url&gt;    
          &lt; snapshots &gt;     
              &lt; enabled &gt; false &lt;/ enabled &gt;     
          &lt;/ snapshots &gt;     
      &lt;/ pluginRepository &gt;     
      &lt; pluginRepository &gt;     
          &lt; id &gt; snapshots &lt;/ id &gt;     
          &lt; url &gt; http: // localhost:8081/artifactory/plugins-snapshots&lt;/url&gt;    
          &lt; releases &gt;     
              &lt; enabled &gt; false &lt;/ enabled &gt;     
          &lt;/ releases &gt;     
      &lt;/ pluginRepository &gt;     
  &lt;/ pluginRepositories &gt;

    但是发现执行maven命令时，maven完全没有从私服上取文件，还是到默认的maven官网去取了。反复修改都不行，最后发现问题可能出现在artifactory上：登录artifactory的控制台后，点Virtual Repositories --》 repo 后直接报错，页面抛ArrayIndexOutOfBoundsException！看url是http://localhost:8081/artifactory/repo/，这个不就是上面配置的地址吗？都抛异常了，让maven怎么取文件，找到问题了，虽然莫名其妙，试着删除后重新安装还是这个错误。晕倒，不清楚哪里出的问题，更不知该怎么改。看看版本是beta1，而且下载数量只有几十，想想可能是新版本的bug。  
    换成1.2.5final，一切都正常了。  
    我想应该是artifactory 1.3.0-beta1的bug吧。

三.maven 的路径变量 M2\_REPO  
     使用mvn eclipse:eclipse命令生成eclipse project后，在eclipse中impot进来，编译出错，原来是maven使用到一个名为“M2\_REPO ”的路径变量。  
     google了一下，eclipse中 设置 变量 M2\_REPO的方式是：  
        Window -&gt; Preferences -&gt; Java -&gt; Build Path -&gt; Classpath Variables ， New Name 填写" M2\_REPO" ，路径为你的本地的 maven 类库地址.

设置后重新编译顺利通过，这样导入eclipse项目就完成了。