本文將 Maven、Artifactory 私服、m2eclipse 插件的安裝配置全過程梳理為標準化操作手冊,適合團隊統一環境、新人快速上手。涵蓋環境變量、代理配置、私服部署、Eclipse 整合、最佳實踐技巧等核心內容。
apache-maven-2.0.9-bin.zip 解壓到安裝目錄M2_HOME = 安裝目錄(不以 \ 結尾)MAVEN_OPTS = -Xms256m -Xmx512m (可選)Path 追加 %M2_HOME%\binJAVA_HOME 正確且 %JAVA_HOME%\bin 在 Path 中mvn --version<proxies>
<proxy>
<id>company-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>iproxy.example.com</host> <!-- 不要加 https:// -->
<port>8080</port>
<username>user</username>
<password>pass</password>
<nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
</proxy>
</proxies>
artifactory-1.2.5.zip (避免 1.3.0-beta1 已知 Bug)bin/artifactory.bat 啟動(需 JDK 5+、JAVA_HOME 正確)https://localhost:8081/artifactory,登錄 admin/passwordetc/jetty.xml 修改端口,etc/artifactory.config.xml 配置 HTTP 代理<proxies>
<proxy>
<key>my-proxy</key>
<host>proxy.example.com</host>
<port>8080</port>
</proxy>
</proxies>
<remoteRepository>
<url>https://repo1.maven.org/maven2/</url>
<proxyRef>my-proxy</proxyRef> <!-- 必須顯式引用 proxy key -->
</remoteRepository>
https://m2eclipse.sonatype.org/update/200807xx)# eclipse.ini 添加 (獨立行)
-vm
C:\path\to\jdk\bin\javaw.exe
# Preferences → Java → Installed JREs
# 添加 JDK 並設為默認,移除 JRE
原因:私服地址可能變更、pom.xml 入版本控制、與具體項目無關。應放在 ~/.m2/settings.xml 或 %M2_HOME%/conf/settings.xml。
<profile>
<id>artifactory</id>
<repositories>
<repository>
<id>central</id>
<url>https://127.0.0.1:8081/artifactory/repo/</url>
</repository>
</repositories>
<pluginRepositories>...</pluginRepositories>
</profile>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
<localRepository>G:/soft/maven/localRepository</localRepository>
如 testng 分 jdk14/jdk15,需指定:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.8</version>
<classifier>jdk15</classifier>
</dependency>
Eclipse: Window → Preferences → Java → Build Path → Classpath Variables → New: M2_REPO = 本地倉庫路徑。解決 mvn eclipse:eclipse 生成項目編譯報錯問題。
初學maven(1)-(5) 進階實戰