Tag Archives: maven

Maven + Jetty + Eclipse + Debugging

Dada la versatilidad que provee Jetty como servidor web por su velocidad de arranque e integración con maven, el cual, a su vez, permite manejar dependencias algunas, he aquí algunas instrucciones para ser capaces de depurar aplicaciones web manejadas por maven desde Eclipse utilizando Jetty como contenedor de Servlets.

Para realizar esto desde eclipse, se debe configurar un external tool:

Dirigirse a External Tools Configuration y crear una nueva configuración, especificando la ruta hacia la instalación de maven local, el working directory y como arguments jetty:run.

Luego dirigirse a la pestaña Environment, y agregar la variable MAVEN_OPTS y asignarle el valor: -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=y

Luego se debe crear un Debug Configuration:

Para crear esta configuración de Debug se debe ir a Debug Configurations, especificar el proyecto que se depurará y el mismo puerto que se estableció en la variable de entorno MAVEN_OPTS

Después de esto se deberán ejecutar los dos de forma consecutiva (uno depende el otro).

Primero se ejecutará la configuración de External Tools, con lo cual en la consola se podrá ver un mensaje como el siguiente en la consola.

Y solo después de ejecutar el Debug Configuration la aplicación comenzará a correr, y estaremos listos para hacer el debugging.

How to get into maven for the first time

Well, I use maven to organize and automatically download project dependencies, basically open source libraries.

With maven you can get a dependency graph like this one(actually generated by eclipse maven plugin):

where your project is the top one.
The best way to grasp easily what maven is, from my point of view is:

To read:

http://maven.apache.org/what-is-maven.html

Download maven:

http://maven.apache.org/download.html

Uncompress it somewhere in the hard disk, create the enviroment variable home M2_HOME to the uncompressed folder.
It is okay to place M2_HOME/bin in the path to use the maven executable (mvn.bat or mvn.sh)

Then integrate it with eclipse or netbeans to actually see how the IDE’s download automatically all project dependencies:

For eclipse galileo, for example:

Install the maven eclipse plugin, from here:

http://m2eclipse.sonatype.org/

(there is an update site for eclipse)

Then add this:

-vm
/usr/java/your_jdk_folder/bin/java

to eclipse.ini for some reason I don’t understand

THen go to: Window > Preferences > Maven > Installations in eclipse and add your recently donwloaded and uncompressed maven installation, select it.

Then you can File > Import > Maven Project and point it to this sample project (with some example dependencies):

http://www.2shared.com/file/9360954/c26ff629/admision.html (download and extract)

Then, you’ll see how eclipse(maven in the background) automatically download the project dependencies under the “Maven dependencies” category that you can check directly in the pom.xml (the file that actually defines a maven project).

For a general view about the maven repositories, this is how a maven repository looks:

http://hl7api.sourceforge.net/m2/

And you can check your own maven local repository at> $home/.m2/repository, in windows c:/Documents and Settings/User/.m2/repository.

Well, I have just a few months with maven, and I’m realizing it is more than a management/build manager, it is fully extensible with your own plugins, allowing you to do almost anything with/from your project sources.

Furthermore, migrating an eclipse/netbeans/etc native project to maven is not too hard, it is usually no more than create a pom.xml file, place there your own project dependencies and move your sources to /maven_project/src/main/java, the resources (log4j.properties, etc) to /maven_project/src/main/resources and unit tests to /maven_project/src/test/java.