Cannot start tomcat as an external tool within eclipse

1.5k views Asked by At

I have configured eclipse to be able to start(for debug: using jpda) and stop tomcat as a program. The first time when i start/shutdown tomcat from eclipse is successful. But the second time when i try to start tomcat i get the following error:

FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: transport error 202: bind failed: Address already in use
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:690]

i think the port is never closed when i run shutdown tomcat from eclipse. If i restart my computer, the ports are released and i can run start tomcat again from eclipse. But everytime i cannot restart my computer to get it to work.. looking for a less radical solution...

This is how i configured my eclipse to run tomcat as a program.

Configured the external tool configuration in eclipse 
catalina script points to catalina.bat on my Windows machine 
under arguments : jpda run
In the Environment tab.
 "JPDA_ADDRESS" as the name and "8000" as the value
 "JPDA_TRANSPORT" as the name and "dt_socket" as the value
 "JAVA_OPTS" as the name and -server -XX:+UseParallelGC -Xmx768m -XX:MaxPermSize=160m -Djava.awt.headless=true as the value
1

There are 1 answers

0
mindas On

I have no idea about how Eclipse works, but it looks like you are trying to bind on the same JPDA port both when stopping and starting Tomcat. When you start Tomcat, then it's obviously fine, but when you attempt to stop it - the stopping can not be done because the port is already taken.

There are many ways to solve this, and these are the ones I personally use:

1) Start/stop Tomcat externally. tomcat/bin/catalina.sh jpda start, tomcat/bin/catalina.sh stop works out of the box without any changes. Maybe Eclipse allows launching external scripts?

2) Start/stop Tomcat as a simple Java program from Eclipse. This way, you won't even need remote debugging as your program will be debuggable as any other Java program. My IntelliJ config looks like this:

Main Class: org.apache.catalina.startup.Bootstrap

VM parameters: -ea -cp $CLASSPATH:/path/to/tomcat/bin/bootstrap.jar -Dcatalina.base="/path/to/tomcat" -Dcatalina.home="/path/to/tomcat" -Djava.io.tmpdir="/path/to/tomcat/temp" -noverify -Xmx400M -XX:MaxPermSize=400M

Program parameters: start

Working directory: /path/to/tomcat

Then you can stop tomcat by simply killing the Java process or create a similar environment with stop as program parameter which will gracefully shut it down. If you look inside catalina.sh, all this script does is really to prepare all these parameters and launch the Tomcat in the same way.