运行环境:Eclipse3.5.2 Maven:2.2.1
步骤1:安装Maven
参考官网: http://maven.apache.org/download.html
Windows 2000/XP
- Unzip the distribution archive, i.e. apache-maven-2.2.1-bin.zip to the directory you wish to install Maven 2.2.1. These instructions assume you chose C:/Program Files/Apache Software Foundation. The subdirectory apache-maven-2.2.1 will be created from the archive.
- Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then adding the M2_HOME variable in the user variables with the value C:/Program Files/Apache Software Foundation/apache-maven-2.2.1. Be sure to omit any quotation marks around the path even if it contains spaces. Note: For Maven < 2.0.9, also be sure that the M2_HOME doesn't have a '/' as last character.
- In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%/bin.
- Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.
- In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line.
- In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:/Program Files/Java/jdk1.5.0_02 and that %JAVA_HOME%/bin is in your Path environment variable.
- Open a new command prompt (Winkey + R then type cmd) and run mvn --version to verify that it is correctly installed.
步骤2: 安装maven eclipse插件
参照官网:http://maven.apache.org/eclipse-plugin.html
步骤3:新建Maven 项目
3.1.可手动建:详细参照官网:http://maven.apache.org/guides/getting-started/index.html
mvn archetype:create /
-DarchetypeGroupId=org.apache.maven.archetypes / -DgroupId=com.mycompany.app / -DartifactId=my-app
3.2.或在eclipse 中右键菜单使用Maven插件
3.3 在pom文件中加入tomcat 插件:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<!-- <url>http://localhost:8080/manager/html</url> -->
</configuration>
</plugin>
步骤四:建好项目后,eclipse中工具栏run下拉菜单选择External Tools ->External Tools Configurations..>
1. 在对话框中新建program
2.Main 面板中输入Mavan 路径 如:D:/apache-maven-2.2.1/bin/mvn.bat
3. Working directory 中输入项目目录
4.Arguments 中输入运行参数 如 tomcat :run
5.Environment中新建参数:MAVEN_OPTS,值为:
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4004,server=y,suspend=y
其中记住address=4004
6。点apply 保存,run运行
pic 1
步骤五:
项目右键菜单启用远程调试: Debug As ->run configurations>
1。新建Remote Java Application,Contenction Properties>Project 项目名称 Host:服务器名称(localhost)Port:端口(4004与步骤四中的address相对应).
2。点debug