总是在tomcat的启动脚本catalina.sh的一开始加上dubug参数,以供远程debug,原参数如下
JAVA_OPTS='-XX:PermSize=728m -XX:MaxPermSize=728m -Xms1024m -Xmx1024m -DNode=DLOG4J
-DProductMode=false -Dfile.encoding=utf-8
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n'
但是这样做后,再运行tomcat的shutdown.sh脚本会报错:
ERROR: transport error 202: bind failed: Address already in use ["transport.c",L41]
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) ["debugInit.c",L500]
JDWP exit error JVMTI_ERROR_INTERNAL(113): No transports initializedFATAL ERROR in native method: JDWP No transports initialized, jvmtiError=JVMTI_ERROR_INTERNAL(113)
以前总是懒得弄,直接killall -9 java 了事,但是现在同一台机器上装了很多服务,不能直接 killall了,用ps -ef | grep java去查又比较麻烦
所以查了一下google,得到结果
You are trying to debug tomcat on startup, so it binds to port 5005 when the jvm starts.
When you run
catalina.sh stop
, it starts up another jvm which also tries to bind to port 5005.You need to move the debug args to the run and start arguments (in
catalina.sh
) of tomcat, putting them straight into theJAVA_OPTS
is the cause of the issue you're having.
最后有一个非常简单的解决方法:
用CATALINA_OPTS 参数替代 JAVA_OPTS 参数
把dubug参数换成:
CATALINA_OPTS='-XX:PermSize=728m -XX:MaxPermSize=728m -Xms1024m -Xmx1024m -DNode=DLOG4J
-DProductMode=false -Dfile.encoding=utf-8
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n'