Apache Maven 的安裝

全球程式

簡介

程式語言

軟體工具

全球市場

程式取得

程式管理

程式運用

資源列表

人物列表

版本管理

SVN

GIT

Mercurial

程式銀行

GitHub

GoogleCode

SourceForge

CodeProject

語言分類

C 語言

C++

JavaScript

Java

Verilog

專案研究

gcc

V8

Arduino

R

UNIXxv6

tcc

OpenGL

GTK

Qt

OpenCV

開發環境

GNU

node.js

icarus

Linux

Windows

Eclipse

VirtualBox

QEMU

CScope

Vim

訊息

相關網站

參考文獻

最新修改

簡體版

English

Apache Maven 是一個 Java 的專案建置程式,就好像 C 語言中的 make 與 Java 的 Ant 等建置器一樣。

要安裝 Maven,請到 http://maven.apache.org/ 下載 maven。

下載:apache-maven-3.0.3-bin.zip,然後解壓縮之,接著同樣看其中的 README.txt 檔案。

...
  Maven is a software project management and comprehension tool. Based on
  the concept of a Project Object Model (POM), Maven can manage a project's
  build, reporting and documentation from a central piece of information.
...
  Installing Maven
  ----------------
  1) Unpack the archive where you would like to store the binaries, eg:

    Unix-based Operating Systems (Linux, Solaris and Mac OS X)
      tar zxvf apache-maven-3.0.x.tar.gz
    Windows 2000/XP
      unzip apache-maven-3.0.x.zip

  2) A directory called "apache-maven-3.0.x" will be created.

  3) Add the bin directory to your PATH, eg:

    Unix-based Operating Systems (Linux, Solaris and Mac OS X)
      export PATH=/usr/local/apache-maven-3.0.x/bin:$PATH
    Windows 2000/XP
      set PATH="c:\program files\apache-maven-3.0.x\bin";%PATH%

  4) Make sure JAVA_HOME is set to the location of your JDK

  5) Run "mvn --version" to verify that it is correctly installed.
...

然後我們根據指示,將 Maven 的 /bin 資料夾路徑加入 PATH (我沒有放在 c:\program files 而是放在 D:\code\apache-maven-3.0.3\bin,因此將 此路境加入到 path。

接著我看到我環境變數中的 JAVA_HOME 指向 C:\Program Files\Java\jdk1.6.0_21\ ,因此沒有問題 (如果指向 JRE 的資料夾,或者不存在 JAVA_HOME 變數,那就有問題了。

然後按照指示,開一個新的命令列,打入 mvn —version 以便看看 maven 是否安裝好了,以下是執行結果。

C:\>mvn --version
Apache Maven 3.0 (r1004208; 2010-10-04 19:50:56+0800)
Java version: 1.6.0_21
Java home: C:\Program Files\Java\jdk1.6.0_21\jre
Default locale: zh_TW, platform encoding: MS950
OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows"

Proxy 的設定

如果您的單位有透過 proxy 管制,就需要為 Maven 設定 proxy 。

我使用 Maven 建置 PDFBox 專案時,就在使用 mvn clean install 開始建置 PDFBox 專案時,出現了下列錯誤訊息。

D:\code\pdfbox\pdfbox-1.5.0>mvn clean install
[INFO] Scanning for projects...
Downloading: http://repo1.maven.org/maven2/org/apache/apache/6/apache-6.pom
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project org.apache.pdfbox:pdfbox-reactor:1.5.0 (D:\code\pdfbox\pdf
box-1.5.0\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for org.apache.pdfbox:pdfbox-parent:1.5.0:
 Could not transfer artifact org.apache:apache:pom:6 from central (http://repo1.
maven.org/maven2): Error transferring file: Connection timed out: connect and 'p
arent.relativePath' points at wrong local POM @ org.apache.pdfbox:pdfbox-parent:
1.5.0, D:\code\pdfbox\pdfbox-1.5.0\parent\pom.xml, line 23, column 11 -> [Help 2
]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildin
gException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableMo
delException

看來像是網路不通的樣子,於是我猜想是因為我在金門大學校內必需設定 proxy 的關係,所以我在 google 用 maven proxy 兩字進行搜尋,找到 http://maven.apache.org/guides/mini/guide-proxies.html 這個網頁,其中記載了下列訊息。

Configuring a proxy

You can configure a proxy to use for some or all of your HTTP requests 
in Maven 2.0. The username and password are only required if your 
proxy requires basic authentication (note that later releases may support 
storing your passwords in a secured keystore - in the mean time, please 
ensure your settings.xml file (usually ${user.home}/.m2/settings.xml) 
is secured with permissions appropriate for your operating system).

The nonProxyHosts setting accepts wild cards, and each host not to 
proxy is separated by the | character. This matches the JDK configuration 
equivalent.

<settings>
  .
  .
  <proxies>
   <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.somewhere.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
    </proxy>
  </proxies>
  .
  .
</settings>

Please note that urrently NTLM proxies are not supported as they 
have not been tested. You may be able to use the relevant system 
properties on JDK 1.4+ to make this work.

於是我們根據指示去找 setting.xml 這個檔案,然後將此檔案的 proxy 這個部份改為本校的 proxy。

  <proxies>
    <proxy>
      <active>true</active>
      <protocol>http</protocol>
      <username></username>
      <password></password>
      <host>proxy.internal</host>
      <port>3128</port>
      <nonProxyHosts></nonProxyHosts>
    </proxy>

然後再用 mvn clean install 指令建置,此時由於是第一次使用 maven,maven 會不斷下載一大堆東西 (真的超久的),大約半小時後才會好。

最後終於建置成功了 (辛苦!)。

Facebook

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License