Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Saturday, May 25, 2013

debugging fornax-oaw-m2-plugin maven plugin

Question: Do you need to debug maven plugin: fornax-oaw-m2-plugin ?
If so, go on reading.

You can find the basic info at their home page:
However remote debugging topic is not covered there.
The problem with maven plugins might be, that sometimes it's not enough to debug maven run itself (as described in my previous post).

However merging information from the previous links with common remote debugging options I came to solution that simply works for me:

<build>
  <plugins>
    <plugin>
      <groupId>org.fornax.toolsupport</groupId>
      <artifactId>fornax-oaw-m2-plugin</artifactId>
      <version>2.1.1</version>
      <type>pom</type>
      <configuration>
        <!-- [BEGIN] debugging related section -->
        <jvmSettings>
          <jvmArgs>
            <jvmArg>-Xdebug</jvmArg>
            <jvmArg>-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8100</jvmArg>
            <jvmArg>-Xnoagent</jvmArg>
            <jvmArg>-Djava.compiler=NONE</jvmArg>
          </jvmArgs>
        </jvmSettings>
        <!-- [END] debugging related section -->
      </configuration>
      <executions>
        <execution>
          <phase>generate-sources</phase>
          <goals>
            <goal>run-workflow</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
Please note that port to remotely connect to with debugger is 8100 in my sample. Feel free to adapt it based on your setup.

After using the configuration in your run, you should get to point where plugin run gets suspended and waits for remote debugger to connect (to find out how to remotelly debug, see some existing tutorial, like this one: http://java.dzone.com/articles/how-debug-remote-java-applicat).

That's it. Enjoy your debugging session.

This post is from pb's blog.

Monday, February 18, 2013

Maven: listing dependencies

Q: Did you ever try to find out all the dependencies in the maven project (even transitive ones)?
A: maven-dependency-plugin should help here.

Following is the command I use to find out:
mvn dependency:tree -Dverbose

Monday, February 4, 2013

Maven: debugging

If you've ever been in the situation that you'd need to debug maven build, these are the options that could help.

Debugging maven run

If you need to debug maven plugins run itself use instead of standard:
mvn <your sfuff>
the debug one:
mvnDebug <your sfuff>
It should tell you it's waiting for connection, in a way like this:
Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000
Afterwards use your preffered way to connect to socket 8000 via remote debugger. (For eclipse steps can be found here, or googled)

Debugging test execution

If you need to debug maven-surefire-plugin run use following:
mvn -Dmaven.surefire.debug test
It would wait for connection, in a way like this:
Listening for transport dt_socket at address: 5005
Afterwards use your preffered way to connect to socket 5005 via remote debugger. (For eclipse steps can be found here, or googled)
Easy, isn't it?

Friday, November 23, 2012

Maven java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher

Have you ever faced exception like this?
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher
Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: org.codehaus.plexus.classworlds.launcher.Launcher.  Program will exit.
My use case was that I had installed maven3 and afterwards tried to use maven2. All the environment variables updates have been setup in:
~/.bashrc
However once trying to use maven2 exception appeared (Even in the new terminal session).
Solution was found based on advice present in: http://cyntech.wordpress.com/2011/03/09/maven-2-error/

Running command:
which mvn
revealed the problem, as I still had in my $PATH the maven3 binary. Even if I appended the maven2, it was there on the later position => maven3 was to be used, but with changed $M2_HOME (reffering to maven 2).

Fixing the $PATH did the job for me.

This might not be your case, therefor as a general sum up of possible root causes, I recommend checking: http://stackoverflow.com/questions/6198677/java-lang-noclassdeffounderror-org-codehaus-plexus-classworlds-launcher-launche

Saturday, February 11, 2012

maven web app development

I came to point where I needed to build simple java based web application that would have as short as possible deployment time.

OK this is the way I had to follow, hope it can help to make your path simple :)

1. The first decision I made was to go for embedded web server => Jetty can do the job.

2. Maven and jetty are friends => can be run using: jetty:run
config details can be found on:
http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin

Where the benefit is that you won't even need to build war (save quite some time during deployment), to have your web app up and running.

3. But I needed to debug when launching from eclipse (using m2e plugin).
Tried a solution with m2e having: MAVEN_OPTS set + remote app debug, as suggested:
http://docs.codehaus.org/display/JETTY/Debugging+with+the+Maven+Jetty+Plugin+inside+Eclipse

this however didn't work for m2e, seems I'm not the only person with this problem, see: http://comments.gmane.org/gmane.comp.ide.eclipse.plugins.m2eclipse.user/7565


4. So I tried: m2e-webby integration:
https://docs.sonatype.org/display/M2ECLIPSE/Integration+with+Maven+WAR+Plugin
and it works great!
It even reads my pom.xml jetty relevant config.

Feel free to spread your experiences in comments section with java web apps development and what is your perfect setup.