`
harborgang
  • 浏览: 17096 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

maven调试

阅读更多
折腾了 将近 4个小时 终于能够调试 maven java工程了。
详情见
http://docs.codehaus.org/display/MAVENUSER/Dealing+with+Eclipse-based+IDE

摘录:(万一网址访问不了)

Dealing with Eclipse-based IDE
Skip to end of metadata
Added by Franz Allan Valencia See, last edited by Ahmet Ekrem SABAN on Mar 03, 2011  (view change) show comment Go to start of metadata
Introduction
There are two ways to use Maven and Eclipse :

1. Use Eclipse as the editor, and Maven command line for commands, or

2. Using an Eclipse plugin for Maven (see Eclipse Integration )

Use the first one if you're much more comfortable with using the command line for your Maven tasks, but would like to take advantage of Eclipse' features ( code complete, refactoring, etc ). Use the second one if you want Eclipse to handle all these things - creation to editing to execution.

For this page, we will discuss the Eclipse plugin for Maven

Setting up
To do so, you must install an Eclipse plugin for maven, see Eclipse Integration.

Debugging your Maven Project in Eclipse
Note that there are two debug modes in maven: the Generic and the Surefire. If you want to debug maven itself, one of maven's plugins, or a maven project, use the Generic Approach. If you want to debug a test in your project launched by surefire, use the Surefire Approach.

Most likely, you're debugging your test so try the Surefire Approach. The Generic Approach is more for maven & maven plugin developers.

Setting up Eclipse
Create a Java Project for the Maven Debug session
Create a new Java Project and call it "Maven Debug". This Project will never have any source code in it, it is just a shell for attaching the debugger.

Create Remote Java Application Debug Configurations
Create two debug configurations, one for Generic debugging called "Maven" and one for Surefire debugging called "Maven Surefire"

Run > Debug... and then right click on Remote Java Application and chose New Launch Configuration.

On the Connect tab click the Browse... button and select the "Maven Debug" project. Make sure that the Connection Properties > Port is 8000. (This matches the address value set on the MAVEN_OPTS command line in the mvn-debug.bat file from above)

On the Source tab click Add... and select all projects that have any Maven source that you want to debug.

Now do the same thing to create a second Remote Java Application called "Maven Surefire" with a port of 5005.

Surefire Debugging
Select break points in the code you're are going to run.

From your command line, append the following to your maven command.

-Dmaven.surefire.debug

For example, to debug the tests run by the Maven lifecycle install, do mvn install -Dmaven.surefire.debug

Wait for Maven to pause its execution and display the message,

Listening for transport dt_socket at address: 5005

Attach the debugger to the running maven by selecting the "Maven Surefire" debug configuration created above.

Generic Debugging
Select break points in the code you're are going to run.

Run Maven in debug mode, e.g mvn-debug install

Attach the debugger to the running maven by selecting the "Maven" debug configuration created above.

Eclipse will now stop Maven at the breakpoints you have enabled.

Setting up Maven 2.0.8+
Note: If you are using Maven 2.0.8 or newer, simply run the "mvnDebug" command in place of "mvn" and skip down to setting up Eclipse.

Setting up Maven <2.0.8
Open %M2_HOME%/bin/mvn.bat

At line 30, you'll find this,

@REM set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000


Uncommenting the line by deleting @REM

Also add

set MAVEN_OPTS=
in the :end section, otherwise the debug will be turned on even when you run the normal mvn.bat

Save that file as mvn-debug.bat (or any convenient name you may want). You now have two Maven batch files, one for normal use, and one for debugging.

Now when you want to debug maven, run mvn-debug instead of mvn (i.e. instead of mvn install, use mvn-debug install)

Trouble Shooting Debugging
Source not found
I "stepped" into a code block and instead of the source I get "Source not found" with an "Edit Source Lookup Path..." button

This occurs because you do not have a project that contains the source for this class. You will need to checkout the source from the Maven subversion repository and then update the source path of the "Maven Debug" project to include this new project.

First you need to locate which project in the repository the class file belongs to.
Chances are this class exists on your classpath for a project. Select from the menu "Navigate > Open Type..." and enter the name of the class that is missing. In the matching types list select the correct class and click OK.

Ensure "Link with Editor" is enabled in your "Package Explorer". With the missing file selected the Package Explorer should have opened the class from a jar file from the classpath of a project. The name of the jar file should help in locating the project in the Maven subversion repository. The SCM location is also contained in the pom.xml file in the jar, this file is located at META-INF/groupdId/artifactId/pom.xml. E.g for the missing file "MavenArchiver.class" this file is contained in "maven-archiver-2.2.jar" and the pom.xml file in "META-INF.maven.org.apache.maven.maven-archiver" lists the SCM connection as "scm:svn:https://svn.apache.org/repos/asf/maven/shared/tags/maven-archiver-2.2".

Checking out the maven project you need and then run mvn eclipse:eclipse.

From the editor with the missing source, click on "Edit Source Lookup Path..." > "Add..." > "Java Project" > "OK" and select the newly checked out maven project.

The source does not match the debug stack trace
It is more than likely that you have a different version on your source path than the one in use by Maven.

The only way to fix this problem is to have matching versions of source to java class files.
This may require checking out the correctly tagged version of the plugin.

However there is no way to determine which version Maven is using as this is handled by the Plexus classworld's class loader.

Debugging Maven Core with Eclipse
See Re: debugging maven with eclipse written by John J. Franey for some setup guidance. Those instructions should be merged into here at some stage.

FAQ
Question:

    1. Why can't I just use Generic Debugging even for my tests?

Answer:

    1. Because maven-surefire-plugin forks a new JVM by default, thus, the your MAVEN_OPTS are not passed. There are three fork modes of maven-surefire-plugin: Once (default), Never, and Always. For Once mode, surefire will run another JVM and will do all its testing there. For Never, it will use the same JVM instance as that of maven (this is normally not use so that you can isolate your tests). But if you really want to isolate your tests, run in Always mode. This will run a new JVM instance for every test sets it runs.

Question:

    2. Will using argLine parameter of maven-surefire-plugin work instead of the -Dmaven.surefire.debug ?

Answer:

    2. Yes. maven.surefire.debug acts like a shorthand version of argeLine=<debugging configuration>. So in most cases, using maven.surefire.debug be enough.
分享到:
评论

相关推荐

    用myeclipse 直接部署MAVEN项目和调试

    同样在“Run As”菜单下,选择“Maven Debug...”,设置好需要调试的配置,如Maven命令行参数和远程调试端口。一旦启动,MyEclipse会在指定端口等待调试连接,此时你可以在源代码中设置断点,当程序运行到这些位置时...

    Maven Reference

    #### Maven调试与配置 Maven提供了多种调试工具和配置选项,帮助开发者定位和解决问题。例如,使用`mvn dependency:tree`可以查看项目的依赖树,帮助理解依赖关系;`mvn compile -X`则可以在编译时输出详细的日志...

    eclipse maven debug

    在Eclipse中配置Maven调试主要有以下几个步骤: 1. **安装Maven插件**:首先确保Eclipse已经安装了Maven插件,如果没有,可以通过Eclipse Marketplace搜索并安装M2E(Maven Integration for Eclipse)。 2. **导入...

    maven-tomcat7集成

    然后,创建一个Maven调试配置,运行目标设为`tomcat7:run-war`,并设置远程调试端口(通常为8000)。在Eclipse的Debug视图中,创建一个新的远程Java应用调试配置,设置主机为本地(localhost),端口为8000。现在,...

    基于外包tomcat的maven实时调试工具

    然而,Maven与Tomcat的集成调试一直是一个让开发者头疼的问题,因为默认配置下,Maven构建的项目并不支持实时调试和热部署,这大大降低了开发效率。标题中的“基于外包tomcat的maven实时调试工具”就是为了解决这一...

    Netbeans jetty maven项目调试配置

    标题 "Netbeans Jetty Maven项目调试配置" 涉及的是在Java开发环境中,如何使用Netbeans IDE结合Jetty服务器和Maven构建工具进行项目的调试配置。这是一个关键的知识点,对于那些经常处理Web应用程序的开发者来说...

    apache-maven-3.6.2_maven_

    在IDE中,开发者可以直接运行Maven命令,查看依赖树,更新项目,甚至进行调试。 总的来说,Apache Maven 3.6.2是一个强大且易用的项目管理工具,它通过标准化的构建过程和自动化依赖管理,极大地提高了开发效率,...

    Maven_web项目非plugin方式调试

    通常情况下,Maven Web项目使用Jetty插件进行调试,但Jetty插件在调试时需要进入debug模式。在某些情况下,开发者可能需要使用其他支持的Web容器来调试运行Maven Web项目,这就需要采用非plugin方式来进行调试。 ...

    maven3.5.4打包文件

    5. **调试与优化**:使用 `-X` 或 `-e` 参数查看详细日志,找出构建过程中遇到的问题。 总结来说,Maven 3.5.4 是一个强大的项目管理工具,简化了 Java 开发中的构建和依赖管理。通过合理利用其特性,开发者可以...

    maven-3.0.5安装包&eclipse-maven插件

    5. **调试插件**:支持对Maven插件进行调试,便于开发和调试自定义插件。 6. **同步Eclipse设置**:M2Eclipse可以与Eclipse的构建路径、JRE设置等进行同步,保持一致性。 7. **支持Maven profiles**:可以方便地在...

    Maven解决jar冲突调试步骤

    ### Maven解决jar冲突调试步骤详解 #### 一、问题背景及理解 在使用Maven进行项目构建时,可能会遇到各种依赖冲突的问题。依赖冲突通常发生在多个不同版本的库被加载到同一个ClassPath中,导致某些类加载出现问题...

    eclipse-maven3-plugin

    5. **调试支持**:通过插件,可以直接在 Eclipse 中调试 Maven 构建脚本,这对于解决构建问题非常有帮助。 6. **目标视图**:在 Eclipse 的“Maven”视图中,可以看到所有可用的 Maven 目标,并可直接运行它们,...

    maven集成jetty所需jar包maven-jetty-plugin,多版本

    而Jetty作为轻量级服务器,启动速度快,适合开发和调试阶段。将两者结合,开发者可以在Maven构建流程中直接启动和测试Web应用,无需额外的服务器配置,提高了开发效率。 2. Maven-Jetty-Plugin介绍: `maven-jetty...

    亲测好用的maven3.zip

    【 Maven3:构建Java项目的强大工具】 Maven3是一个广泛使用的Java项目管理工具,由Apache软件基金会开发。它简化了构建、依赖管理和项目文档的生成,使得开发人员能够更高效地进行软件开发工作。Maven3的核心理念...

    maven开发环境搭建

    ### Maven开发环境搭建详解 ...通过上述步骤,你可以成功地在Eclipse中搭建基于Maven的Java Web项目开发环境,并进行调试和服务配置。这不仅能够提高开发效率,还能够帮助开发者更好地管理项目的依赖关系。

    maven3.6.3.zip

    5. **调试与优化**:通过`mvn dependency:tree`查看依赖树,排查冲突;使用`mvn -X`开启详细日志,定位问题。 总的来说,Apache Maven 3.6.3是Java开发中的重要工具,它的强大功能和标准化的构建流程极大地提高了...

    maven-jetty-plugin

    1. **快速开发和调试**:通过在IDE中直接运行Maven Jetty Plugin,可以实时观察代码更改的效果,无需每次都打包和部署。这对于迭代开发和快速调试非常有用。 2. **动态部署**:在开发阶段,Maven Jetty Plugin能够...

    apache-maven-3.5.2.zip

    4. **更好的用户体验**:可能改进了命令行接口,或者对日志输出进行了优化,使开发者更容易理解和调试构建过程。 为了使用"apache-maven-3.5.2.zip",你需要首先在命令行环境中使用`unzip`命令来解压缩文件。解压后...

    android maven

    同时,Android Maven插件也支持调试Android应用,只需在命令行添加`-Dandroid.emulator.debug=true`即可。 **五、持续集成** 由于Android Maven插件与Maven生态系统兼容,因此很容易与Jenkins、Travis CI等持续...

    maven配置.docx

    4. 调试与测试:IDEA支持直接运行和调试Maven的测试类,也可以配置Maven目标来运行集成测试。 5. 插件管理:在"Pom.xml"中配置Maven插件,IDEA会提供插件的图形化界面供你使用。 总之,Maven的配置和使用是Java开发...

Global site tag (gtag.js) - Google Analytics