最近一些项目需要让Maven来管理,一种情况是将之前的eclipse的Java Project项目和Web project 加入Maven管理,还有一种情况是,将SVN上的Maven项目拉到本地,在eclipse中使用时遇到的一些棘手问题,问题过程和解决具体方案如下: 1.在eclipse中安装maven插件后启动eclipse时,会遇到如下警告:
The Maven Integration requires that Eclipse be running in a JDK, because a number of Maven core plugins are using jars from the JDK
Please make sure the -vm option in eclipse.ini is pointing to a JDK and verify that Installed JRE’s are also using JDK installs. 2.使用maven插件在eclipse中编译或者Maven Install时有时会出现会出现如下问题:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project springside-core: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK? 以上两个问题解决方法如下:
(1)set your JDK as a default Java environment in eclipse (default installed JRE)
Open eclipse. Click on ‘Window’ -> ‘Preferences’ -> ‘Java’ -> ‘Installed JREs’.
If you can’t find any JDK on the list -> click ‘Add’ -> ‘Standard VM’ -> set all paths and click ‘Finish’.
After that – check this JDK on the list of installed JREs and click ‘OK’.
有时采取第(1)种方案并不能有效解决问题,还需要如下处理:
(2)add path to your SDK in eclipse.ini
open ‘eclipse.ini’ and add there: -vm path_to_javaw_on_your_machine,so in my example it will be (jdk1.6.0_17 on Windows):
-vm
D:\\Java\jdk1.6.0_13\jre\bin\javaw
your ‘eclipse.ini’ looks like this:
-startup
plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
-vm
D:\Java\jdk1.6.0_13\jre\bin\javaw
-vmargs
-Xms40m
-Xmx256m 注:‘-vm’ must be "-vmargs" above 3.使用Maven,经常会自己搭建nexus私服,具体步骤如下:
建立私服的优点:
(1) 降低中央仓库负荷
(2) 节省外网带宽
(3) 加速Maven构建
(4) 自己部署构件
1). Nexus安装
(1) 下载:http://www.sonatype.org/nexus/,下载包:nexus-2.0.2.war
(2) 安装
A. WAR方式安装Nexus
将nexus-2.0.2.war拷贝至Tomcat的部署目录:C:\Apache-tomcat-7.0.26\webapps下,
启动Tomcat, 进入Tomcat管理首页即可;
浏览器访问地址:http://localhost:8080/nexus
B. Bundle方式安装Nexus
因为Bundle方式的Nexus默认集成了Jetty容器,因此不需要其他第三方Web容器,解压下载的Bundle
方式的Nexus文件,有下面的两个目录:
nexus-webapp-2.0.2:包含Nexus所需要的文件,如启动脚本,依赖JAR等。
sonatype-work:包含Nexus生成的配置文件、日志文件、仓库文件。
WinOS下,进入nexus-webapp-2.0.2/bin/jsw/windows-x86-32运行nexus.bat脚本启动服务。
浏览器访问地址:http://localhost:8081/nexus
备注:
更改访问端口:修改nexus-webapp-2.0.2/conf/plexus.properties
(3) 登录
Nexus默认的管理员及密码:admin/admin123
2). Nexus的仓库与仓库组
Nexus有四种仓库类型:group,hosted,proxy,virtual,仓库格式为:maven2或maven1,仓库属性Policy为:Release或Snapshot. 3.设置本地Maven库步骤和在eclipse中使用Maven遇到的一些问题及解决方案如下:
以下是在D:\Java\apache-maven-3.0.1\conf的settings.xml文件中配置,maven的settings.xml是全局设置,下面会在eclipse中使用该自定义的maven:
1).设置本地Maven库地址:
D:/Java/maven_repository
2).建立nexus私服后,设置访问服务器的账号和密码: