Java Debugging Deployed Glassfish #PostConstruct Unable to Debug - java

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...

Related

Running Weblogic Server in Debug mode on IntelliJ in Windows 10

I am trying to run Weblogic server on IntelliJ in debug mode. But I get the following exception
Method threw 'java.lang.NullPointerException' exception. Cannot evaluate weblogic.management.configuration.DomainMBeanImpl.toString()
I tried deleting all the deployments through IntelliJ and config.xml file, still I get this issue.
However Weblogic is able to run fine when not in Debug mode.
Please feel free to reach out for any further clarifications.

IntelliJ is not running Spring Boot Debugger

I am trying to debug a Spring boot project with IntelliJ. Suddenly, my lines do not debug after working for last few years.
It will debug through the class, but when i try to run a method, it will not see the breakpoint. I got an application context message earlier, which I fixed, but its still not working. https://www.jetbrains.com/help/idea/2021.2/spring-support.html#spring-file-set
It will see/execute these lines in the background (like its one another thread), but not will debug/catch the method lines.
#Autowired
public EncounterFacade(SuperbillRepository superbillRepository, EncounterRepository encounterRepository) {
this.superbillRepository = superbillRepository;
this.encounterRepository = encounterRepository;
}
Currently using a Mac system. It was already running Local host port in the background,
Ran npx kill-port 8080 to resolve the issue and it worked.

Catch external jar stop event for Spring-boot application with Intellij Idea

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.

How to start Apache Zeppelin in debug mode?

I need to start Zeppelin in debug mode in order to add breakpoints in Intellij to remote debug the code.
How do I do this? There is no documentation available on this.
You can set this property
In zeppelin-env.sh
export ZEPPELIN_MEM="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8111"
Similarly you can do for interpreter-mem
Only catch is you can remote debug only one intrepreter process since there are no unique properties for each interpreters.
See How to contribute page for details about debugging.
First, let's update zeppelin-env.sh to properly set the configuration to get the JVM to start in debug mode.
Edit $ZEPPELIN_HOME/conf/zeppelin-env.sh
Add the following to the file:
export ZEPPELIN_MEM="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8111"
Now that we have updated the zeppelin-env.sh, the next time Apache Zeppelin starts, it will be listening for a remote debugger on port 8111.
To debug an interpreter, update ZEPPELIN_INTP_MEM envrionment variable instead.
But as Ram has already mention, it would only work for one interpreter, because of port conflict.
Configure IntelliJ IDE to connect and debug the remote Apache Zeppelin
Go to Run->Edit Configuration
Create a new remote configuration in your IntelliJ IDE:
Configure IntelliJ to stop on exceptions
Go to Run->View Breakpoints
Enable 'Java Exception Breakpoints'
Select condition checkbox, and add the following condition :
!(this instanceof java.lang.ClassNotFoundException ||
this instanceof java.util.MissingResourceException ||
this instanceof javax.naming.NoInitialContextException ||
this instanceof java.lang.NoSuchMethodException)
You should now have Exception breakpoints configured like:
Full credit goes to Luciano Resende - see complete article here:
http://lresende.blogspot.com/2016/08/launching-apache-zeppelin-in-debug-mode.html

Remote debugging using Eclipse - How to set breakpoints?

I asked this question about how to debug server side applications and I think I was looking for Java remote Debugging.
I have configured my server side startup script:
JAVA_OPTS="-Xmx2G -server -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n"
By this, I assume the remote java app should be available on localhost:1044 (try it first using localhost)
But, what do I do next? I have configured the debug options to the class to be debugged via Run-->Debug Configurations. But it asks me to click Debug. But my class does not have a main() method.
Say, I want to debug getValue() in Methods.java, now getValue() is invoked from a client (via tcp).
So, how do I attach the java process to eclipse remote debugger when that method is invoked? Am I missing out on something basic about remote debugging?
UPDATE: (I can see this in my debug view, that means, the remote app is connected and in the debug mode, now how do I put a breakpoint in the file where I want)
Add the line below:
-agentlib:jdwp=transport=dt_socket,address=1044,server=y,suspend=n
to run eclipse in debug mode
For eclipse, click on debug as icon > debug configurations > add a new remote java application > change the project to the project that you need and port to 1044 and click on apply and debug.
Put your breakpoint and access the remote application

Categories