买了一本《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插件
三、配置maven和nexus
<?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项目
五、问题
[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.
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 。系统不知道用哪一个。这个时候可以设置一下或者删除一个只用一个