How to set agentlib property for mvn tomcat plugin (jpda) - remote-debugging

Related to
eclipse debug remote web application => How do I debug a remote application in my eclipse
How can I set / archive this in the mvn tomcat plugin?
http://tomcat.apache.org/maven-plugin-2.0-SNAPSHOT/tomcat7-maven-plugin/
The only thing that might help is setting systemProperty but that doesn't work for me ;/
Goal: let tomcat run on console via maven but enable remote debugging for different IDEs
(YES guys, we can run tomcat in Eclipse WTP! That's not the question ;)

$ export MAVEN_OPTS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
$ mvn tomcat7:run-war
^^ that's it, not cool (as it is not in POM) but it works
Source: http://aaronz-sakai.blogspot.de/2009/02/debugging-jetty-when-running-mvn.html

It's a bit old thread but for the sake of completeness I though i might add a little here.
The plugin does not provide debug options configuration for whatever strange reason.
Thus your only option is to manually specify debug configuration to the JVM that runs the process.
In your environment, there are three ways achieve this:
Using a well known-maven environment variable (as described by childno.de)
Directly specifying the options to maven (no env. variable needed):
mvn -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y tomcat7:run-war
With an eclipse Run configuration That's basically the same like 2) but you define this in eclipse (that would be good if you didn't want to leave the IDE at all).
To achieve that you need to specify a Maven Build Run configuration.
Set the goal to tomcat7:run (or similar) and then navigate to the JRE tab. The VM arguments area is where you specify the debug configuration: -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y
If you opt for 3), the precise run goal for tomcat7 is irrelevant to the debug enabling. Choose according to you use case (dynamic web project, war, etc.). Same goes for the plugin configuration. However, make sure to specify that you are using the tomcat maven plugin in the pluginManagement section of your project pom:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</pluginManagement>

OR... you could simply add the following tag to your plugin configuration
<jpda>true</jpda>
Then when you execute: mvn tomcat7:run, it will start jpda on port 8000.
Funny thing is even though I have tested this and it works, I can't find any code in the opensource code base to explain why it works, nor have I found any way to change from the default port 8000.
Apache seems to have dropped the ball when it comes to documentation of this plugin.

Related

Unable to execute unit tests in a maven project from within intellij

I have inherited a legacy project with 100s of tests, and dependencies defined within the pom.
All of the tests run when I execute a mvn clean install from the command line, but when I try to execute one of these tests in debug mode from within Intellij i get the following error.
java.lang.NoClassDefFoundError: Could not initialize class
How can I get intellij to recognise these dependencies when trying to run a test in debug mode from the ide?
I managed to solve this by simply changing the working directory location in the Run configuration to point to the correct classpath location. The default location had been taken from a parent project.
It would be very convenient if one was able to debug tests from within IntelliJ. I have run into similar issues with my massive project and have found a workaround for it.
When wishing to debug a test, I have often found it useful to use a remote debugging session like so:
mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE" -Dtest=com.autofunk.TheFunkImplTest test -DfailIfNoTests=false
You can then attach to the above using a remote debug session from within IntelliJ on port 8000.
Therefore, when debugging tests I first check to see whether a simple debug from within Intellij works. If not, I run the above and then attach to it using a debug configuration like so:
IntelliJ execute unit tests without mvn command.
a IntelliJ plugin: MvnRunner
You can run tests using the maven project window in IntelliJ
View - Tool Windows - Maven Projects
Then under the project or module you wish to test open the lifecycle goals and click test.
This will run the currently configured test goal. Now the report is logged into the target directory
I use
https://github.com/destin/maven-test-support-plugin
to view the test results.
You can access this screen once the plugin is installed from the Project window again right click on the projects root and select "Show Test Results" (should be below the maven icon)
Good luck

Jetty server best IDE

I want to use Jetty 8.0 Server for my application. Which IDE i will use for simple configuration.
Presently i am using Eclipse. How to configure jetty in Eclipse. Any best example?
I use run-jetty-run, and jetty with maven in eclipse.
http://code.google.com/p/run-jetty-run/
More on jetty maven plugins:
http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin
I use run-jetty-run with DCEVM for hotdeploy.
Here's my tutorial, Spring-mvc + Velocity + DCEVM
Most people I know simply write a small embedded usage of jetty for their application. It is dead simple to do and there are a number of examples in the example-jetty-embedded project in jetty git repository. It is also how most of our test cases are written, using jetty itself to test.
http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/example-jetty-embedded
If your using maven then the jetty-maven-plugin is a pretty simple way of testing and works with the eclipse plugin Webby which streamlines much of the pain and suffered that is called WTP.
https://docs.sonatype.org/display/M2ECLIPSE/Integration+with+Maven+WAR+Plugin
There is also a Jetty WTP plugin that many people use successfully.
http://wiki.eclipse.org/Jetty_WTP_Plugin
I also use run-jetty-run for Eclipse.
I tried the Jetty plugin for NetBeans, but it didn't work.
I think Jetty for Eclipse is better than Tomcat, cause its simpler to use and configure and a fast server.
Assuming you have setup M2Eclipse plugin within Eclipse correctly and your project is configured to use Maven, I've found Jetty Maven Plugin within Eclipse to be particularly useful. The beauty of this approach is that you can do your development really fast, especially if you have 3rd party dependencies. All you have to do is add the following plugin to your pom.xml:
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.8.v20121106</version>
<configuration>
<contextPath>/</contextPath>
</configuration>
</plugin>
...
</plugins>
</build>
...
</project>
To use this plugin successfully here some additional notes on installation and usage:
Eclipse Integration
Install the following Eclipse Plugins first
Maven Integration for Eclipse (Help > Eclipse Marketplace...)
A patch that makes it possible to debug source code at runtime. Eclipse Plugin Link
Next, create a "Maven Build" Eclipse Launcher
You also need to configure "Maven Build" launcher so that you can run the Jetty Server quickly. Follow the instructions below create this launcher:
Right-click on your current project and select (Run As/Debug As) > Maven Build...
Set Goals As rhubarb:start
Check Resolve Workspace artifacts
Save
Going forward, you can simply do: (Run As/Debug As) > Maven Build, and the goal will execute.

Maven jetty plugin,how to do this:modify the class with out restart server

Some days early,my pm asked us to use maven and jetty to development and debug the app,but i had never used them any more.
Right now , i can't to hot deploy the app with out restart the jetty,if i modify the app with restart the jetty every time ,i will be crazy.It waste lot of time.
So,i hope somebody can help me that,how to config this.
Thanks.
This is my jetty-maven-plugin setting. When you recompile your code, the plugin will check every 10 secs to reload the new classes.
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.4.5.v20110725</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
</plugin>
When I was using maven 2 and maven jetty plugin 7.4.5 it worked fine, but after migrating to maven 3 it didn't work anynore.
A simple -yet not optimal solution- that i found in another forum consists in using this entry
in the configuration of the plugin:
<reload>manual</reload>
Althoug it doesn't fix the issue of automatically hot-redeploying your app if any change is detected, it allows you to restart you app by simply hitting the "enter" key.

IntelliJ IDEA debugger skips breakpoints when debugging Maven tests

I am trying to debug Maven tests in IntelliJ IDEA. When I open IDEA's Maven Projects view and right-click on test goal, I get an option to debug it. Clicking it executes this goal but the execution never stops at any breakpoints. What am I missing?
Thanks.
Just disable the forked mode - something like this in your pom file (under project/build/plugins section):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
<configuration>
<forkMode>never</forkMode>
</configuration>
</plugin>
One solution would be to use remote debugging:
configure the surefire plugin: <debugForkedProcess>true</debugForkedProcess>;
run the test (will wait for a remote debugger to connect)
create and run a remote debug configuration in IntelliJ (will hit your breakpoint); the port to connect to is 5005.
If you're running unit tests with maven failsafe rather than surefire, then debugger will not stop and you have to manually run a failsafe debugger command line and then intellij will be able to stop on the breakpoints. I am unsure if using <forkMode>never</forkMode> option on failsafe solves this issue.
As I describe here: https://github.com/djangofan/maven-failsafe-debug-example
Your sources for the dependencies do not match the binary code. Make sure you're using the same sources.

Tapestry webapp with embedded Jetty

How can I configure a Tapestry5 project to run standalone (via java -jar) with embedded Jetty?
I'm looking for a short "recipe" regarding Tapestry5, Jetty, configuration of servlets/ handlers/ whatever is needed to connect the dots...
I've seen a few dots: How to Create an Executable War, Configuring Tapestry (ref Tapestry as servlet filter)
Edit: I'm thinking about a standalone running webapp due to server circumstances. It doesn't have to be embedded Jetty, but I can't rely on a stable appserver. Still looking for a recipe, though, so I don't spend much time on dead ends...
Also, I'd like for Jenkins (Hudson) to be able to stop and start the server automatically when deploying updates - I don't know if that influences what I can do with Jetty, f.ex.
Well, i believe this is a general "how to run a war question". Assuming you indeed have a war, you can use jetty or winstone to "run" it - see :
http://winstone.sourceforge.net
and
http://www.enavigo.com/2008/08/29/deploying-a-web-application-to-jetty/
In the first case, you can directly do
java -jar winstone.jar --warfile=<warfile>
https://github.com/ccordenier/tapestry5-hotel-booking/
<-- Check its maven build
http://tapestry.zones.apache.org:8180/tapestry5-hotel-booking/signin
I did some digging, and this is the short recipe I basically ended up following:
Start with the Maven Jetty plugin as configured in the pom.xml of the Tapestry 5 archetype
Add the stopKey and stopPort attribute to Maven Jetty plugin configuration
Let Jenkins CI run maven target jetty:stop and then clean install
Let Jenkins run shell script mvn jetty:run &
Voila - my Java app is up and running with automatically updated code, without any appserver.