When I start my Tomcat 7 from Eclipse, I usually add something like
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8101
to its launch configuration, since I sometimes want to attach the Eclipse debugger remotely later. But when I do this and try to shut down the Tomcat from Cclipses "servers" view, I receive the 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
I assume this is because Eclipse starts a new process that normally tells the running Tomcat to shut down, and also uses the debugging arguments I introduced in to the launch configuration. This process fails, since the named port 8101 is already used. Does anybody have an idea to allow a clean Tomcat shutdown in that setting?
(I do not want to start the Tomcat in Debug mode in the first place since that slows down both eclipse and the Tomcat. Neither do I want to restart it in debug mode when I want to debug, since that takes quite some time.)
In Tomcat's server.xml
<Server port="8005" shutdown="SHUTDOWN">
The setting can be used to shutdown Tomcat. You can write a simple program and run it.
import java.net.*;
public class t {
public static void main(String[] args) throws Exception {
Socket s = new Socket("127.0.0.1",8005);
s.getOutputStream().write("SHUTDOWN".getBytes());
s.close();
}
}
Related
to launch my Spring Boot application in production environment my company has a system that executes "java -jar" and I'm trying to simultate it in my Intellij idea and jar starts correctly and I can debug with proyect source too.
In run and debug mode, when I click in stop button the jar is stopped suddenly with the message:
Disconnected from the target VM, address: '127.0.0.1:58575', transport: 'socket'
Process finished with exit code -1
And I canĀ“t catch the close event to close my DB connections. I've tryed other stackoverflow solutions like PortalServiceLifeCycle, #PreDestroy and setRegisterShutdownHook(false) in SpringApplication run in main.
Jar is created by Maven with clean and package goals and we haven't xml spring configurations, only annotations.
What I need to catch shutdown service to close connections?
Edit: Add my Intellij buttons:
Thank you.
Please check this answer.
This feature is not available in Debug mode yet.
This feature is also not available for JAR run configuration, but is available for Application run configuration.
You can use remote debug and Ctrl+C in the external console to debug the code in the shutdown hooks until IDEA-171093 is implemented.
I can debug a Java application in NetBeans and have debugged other projects in NetBeans. However, when deploying a Singleton in Glassfish and setting a breakpoint on the #PostConstruct annotation I am unable to debug. I have set the target server to debug on and I set the breakpoint where the debugger should debug from and I start the server in debug mode. However, I am still unable to debug in NetBeans. Below is the code:
#Startup
#Singleton
public class Listener {
#PostConstruct
public void init() {
System.out.println("init");
}
}
I set the breakpoint on the System.out.println("init") statement. The steps that I follow are:
1) Build Jar file
2) Start Glassfish server
3) Deploy the Jar file
4) Start the server in Debug mode
5) The "init" is printed in the Console in NetBeans but I am unable to debug.
I have tried attaching a debugger on many different ports, but I either get connection refused or it can't debug.
I am using NetBeans 1.7.2. I have tried the same with other versions of NetBeans but still the same problem.
The above is only a sample code, but there is more code but I am unable to debug. I can't find any solution on Google.
Could you give this a try?
You have to:
Start server in debug mode (when it start's dt_socket port is printed)
Attach debugger Debug -> Attach Debugger...
Set breakpoint
Deploy your app
#PostConstruct is called during deployment, so the order of steps you provided is incorrect, because the code is invoked before you attached to debugger.
Did you try this with eclipse?
As I remember, I had no problem in debugging the #PostConstruct method in eclipse.
On more thing to mention:
- A #Singleton bean lives as long as your application lives on the server... So if you want to debug its #PostConstruct, I would suggest opening the glassfish server console, and using the disable application option from console... until that, the #PostConstruct won't be called, since the bean is container managed...
I'm getting the following error when I try to debug a simple local "Hello World" application. But the same application runs fine.
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: transport error 202: connect failed: Connection timed out
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:750]
Debugging local applications used to work on my Eclipse (Kepler on Windows 7). I'm able to ping localhost.
I tried:
Turning off firewall.
Changing JRE libraries. (changed to jdk)
Doing a clean Java Installation.
Uncommenting "127.0.0.1 localhost" in etc\hosts
The issue is still not resolved. Is there anything else I can try.
The issue has been resolved. I had recently upgraded Avast Antivirus. Avast 2014 was causing the issue. I had tried deactivating Avast, but this did not fix the issue. Uninstalling Avast completely fixed the issue. I have switched to Avira now.
This question already has answers here:
Eclipse Error: "Failed to connect to remote VM"
(26 answers)
Closed 9 years ago.
When ever i tried to launch my eclipse debug(for server side code) i'm getting the following error Failed to connect to remote VM. Connection refused.
What's the problem may be? I already tried with most of the solutions out in the web but none of that solved my issue. Could any one can assist me to fix this? Advance thanks..
when you have Failed to connect to remote VM Connection refused error, restart your eclipse
Which server are you using?
Like already said:
In your debug configuration you'll have to define the right port of your server (GF:9009 / Tomcat:8000)
You'll have to set the JVM property of the server to debug
For Glassfish:
Log in to admin-console > Configurations > server-config > JVM-Settings > check DEBUG checkbox > restart server
For Tomcat:
create file debug.bat/.sh (depending on your OS) in %TOMCAT_HOME%/bin directory and write
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
catalina.bat jpda start
in it.
After you've created this file start server by executing debug.bat/.sh.
Now you should be able to debug remotely in Eclipse after you set the necessary properties in your debug configuration.
Hope this helped! Have Fun!
EDIT
If you're running tomcat in a Win environment as a service you don't have a catalina.bat file in the bin-directory of your tomcat installation.
To set your server into debug-mode please try the following:
Run the Configuration option in Windows Menu or run %catalina_home%/bin/tomcat6w.exe
In Java tab, add this line to Java:
options:-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
Sometimes the port which you are trying to access, gets occupied and won't be released.
Try some tools to find whether the port is in use or not.
I also faced the same issue. I tried giving different port numbers but unfortunately it didn't work. I tried restarting the system (not the application server), and it worked :)
I faced the same issue. But i resolved it by changing my port numbers to different one.
The port number in the Eclipse configuration and the port number of
your application might not be the same.
You might not have been started your application with the right
parameters.
Those are the simple problems when I have faced "Connection refused" error.
As suat said, most of the time the connection refused is due to the fact that the port you set up is in use or there is a difference between the port number in your remote application debugging configuration in Eclipse and the port number used in the address attribute in
-Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n.
Check those things. Thanks!
If you need to debug an application working on Tomcat, make sure that your Tomcat-folder/bin/startup.bat (if using windows) contains the following lines:
set JPDA_TRANSPORT="dt_socket"
set JPDA_ADDRESS=8000
call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%
I ran into this problem debugging play framework version 2.x, turned out the server hadn't been started even though the play debug run command was issued. After a first request to the webserver which caused the play framework to really start the application at port 9000, I was able to connect properly to the debug port 9999 from eclipse.
[info] play - Application started (Dev)
The text above was shown in the console when the message above appeared, indicating why eclipse couldn't connect before first http request.
I am currently running jetty from eclipse as an external java program. The problem is when I terminate jetty and I try to relaunch it again, it cannot due to the port still being in use.
What I have to do is open up Windows Task Manager and kill the java process manually. How do you get jetty to shutdown/terminate/end nicely?
The following are my maven jetty application settings
Arguments: jetty:run-war
MAVEN_OPTS: -Xdebug -Xnoagent
-Djava.compiler=NONE -Xrunjdwp:transport=dt_socket, address=8080,server=y, suspend=y
Setting suspend=n doesn't seem to solve the problem either.
If a java application does not shutdown it is because of an alive non-daemon thread. Try getting a thread dump of the running maven process, e.g. using VisualVM and see what keeps the application alive.
You could run the application via the 'Run Jetty Run' Eclipse plugin, rather than the Maven jetty plugin. Eclipse has more direct control over the new JVM then.
I'm not familiar with the maven plug-in, but when starting jetty with start.jar, you can use stop.jar to have it shutdown gracefully (since version 4.something).
Stopping Jetty
Programs started with the start.jar mechanism may be stopped with the
stop.jar:
java -jar stop.jar
This connects via a local port to stop the server. The default port can be set
with the STOP.PORT system property
Source
Alternatively, and maybe more to your liking, you can do it within eclipse by writing a class like this, and running the main method:
package mypackage;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
public class Stop {
public static final int PORT = 8079; //Change to whatever your port is, 8079 is default
public static void main(String[] args) throws Exception {
Socket s = new Socket(InetAddress.getByName("127.0.0.1"), PORT);
OutputStream out = s.getOutputStream();
System.out.println("*** sending jetty stop request");
out.write(("\r\n").getBytes());
out.flush();
s.close();
}
}
Source
It seems that I forgot to tick "Allow termination of remote VM". Strange that it didn't seem to work before.