Maven在Eclipse中使用調試

運行環境:Eclipse3.5.2 Maven:2.2.1 

步驟1:安裝Maven

 

參考官網: http://maven.apache.org/download.html

Windows 2000/XP

  1. 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.
  2. 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.
  3. In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%/bin.
  4. 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.
  5. 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.
  6. 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.
  7. 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 


   

  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章