3

I am currently developing an MVC Application using Java EE Technologies and Eclipse as an IDE. To run my server and deploy my application I am using ANT. I would like to know how can I debug my Java Code through the ant tool or eclipse.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
user1084509
  • 1,832
  • 10
  • 33
  • 48

2 Answers2

2

Add the following jvmarg options to your tomcat start command:

<jvmarg value="-Xdebug"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n"/>

You will be able to attach the Eclipse debugger on port 5000, using the Remote Java Application debug category.

Strelok
  • 50,229
  • 9
  • 102
  • 115
  • Is it easier to run it from Eclipse without using ant? What should I do for that? In ANT I had configured all my external Jars to be in WEB-CONTENT/WEB-INF/LIB, but I imagine that in order for being able to run it directly from Eclipse, I sould place this external libraries somewhere else. – user1084509 Dec 07 '11 at 23:13
  • @user1084509 I prefer to run everything from `ant` because this way you already have everything configured and you don't need to maintain ant and Eclipse in sync. You can add the `ant` view window to eclipse and just run your ant task from within Eclipse. – Strelok Dec 07 '11 at 23:16
1

You can do that from eclipse:

See here for details.

But it is not a good idea to use ant to start tomcat in development. Use Eclipse WTP to start your tomcat and deploy applications on it.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • Thank you very much for your answer. As I mentioned before, Im using ANT to start apache. Do you know how can I enable debug mode in tomcat via my ant start command? My ant task looks as follows: Starting Tomcat – user1084509 Dec 07 '11 at 23:00
  • you'd have to add the debug configuration in your catalina.sh/bat – Bozho Dec 07 '11 at 23:02
  • I would like to follow your advice of not using ANT. I already configured my server in Eclipse, the problem now is that when trying to run my application, it doesn't find any servlet. What should I do to compile my classes, build the proyect and start running it? The option Project - Build all is disabled – user1084509 Dec 07 '11 at 23:11
  • you have to configure the deployment assembly of the project. Look for a WTP tutorial to see how – Bozho Dec 08 '11 at 06:57