Category Archives: Maven

If you are developing on top of Apache Solr, you might consider integration Solr with your maven build, by launching it from the maven-jetty-plugin. This brings several advantages, such as the possibility to shorten the time to get started in the project, unify the dev environment of the team with a fixed Solr version, do automated integration tests by launching and stopping Solr in the pre/post integration-test phase of the lifecycle and also creation of a single WAR contained the standard Solr with the custom plugins and configuration.

Here’s a way to do it:

1) Since solr.war is not yet available on public maven repo (SOLR-1218) make sure you deploy the solr.war file in any of your maven repo. In this post I’ll assume that solr.war is found inder org.apache.solr:solr-webapp:1.4.0 of you maven repo.

The maven jetty plugin is a handy plug-in that allows to run a maven based project that has a web-app inside simply by doing a “mvn jetty:run”, without the hassle of creating a WAR and deploy it to somewhere else.

Who uses maven as I do for a long time, knows that sometimes things does not go as expected. So it’s necessary to look at the ultimate documentation: the source code! In this post I’ll show how to debug a maven plugin using Eclipse’s remote debugger. I’ve chosen for this example the maven-clean-plugin.

Ok, let’s start. First create a simple sample project:

mvn archetype:create -DgroupId=com.wordpress -DartifactId=maven-debug

In the folder maven-debug, edit the pom.xml and add the dependency of the plugin. This will serve as an “anchor” to bring all the sources needed to debug.

Note the scope “provided”, meaning that the dependency will be given to the project by someone and it should not make to the final package. It shouldn’t matter, anyway, since this is a dependency that will be removed later, it’s just for debug purposes.

It’s important to know what version of the plugin your project is using. When in doubt, run “mvn -X clean” and note lines like:

[DEBUG] Retrieving parent-POM: org.apache.maven.plugins:maven-plugins::3 for project:
null:maven-clean-plugin:maven-plugin:2.1.1 from the repository.

Now generate the project in eclipse:

mvn -Declipse.downloadSources=true eclipse:eclipse

Open eclipse, go to File -> Import -> Existing Projects into Workspace and select the root directory of the project. After that go to menu
“Run –> Open debug dialog” and under “Remote java application” create a new profile to debug our project:

Using the eclipse search facilities, search for a class which name ends with “Mojo” (Maven Old Java Object) and place a breakpoint in the “execute” method. In the case of the clean plugin, this class is called CleanMojo

To debug, first enable debug on maven in the command line (linux shown here)