简体   繁体   English

Java调试已部署的Glassfish @PostConstruct无法调试

[英]Java Debugging Deployed Glassfish @PostConstruct Unable to Debug

I can debug a Java application in NetBeans and have debugged other projects in NetBeans. 我可以在NetBeans中调试Java应用程序,并在NetBeans中调试其他项目。 However, when deploying a Singleton in Glassfish and setting a breakpoint on the @PostConstruct annotation I am unable to debug. 但是,在Glassfish中部署Singleton并在@PostConstruct批注上设置断点时,我无法调试。 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. 但是,我仍然无法在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. 我在System.out.println(“ init”)语句上设置断点。 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. 1)构建Jar文件2)启动Glassfish服务器3)部署Jar文件4)以Debug模式启动服务器5)NetBeans的控制台中打印了“ init”,但是我无法调试。

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. 我正在使用NetBeans 1.7.2。 I have tried the same with other versions of NetBeans but still the same problem. 我已经尝试过与其他版本的NetBeans进行相同的操作,但是仍然存在相同的问题。

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. 我在Google上找不到任何解决方案。

Could you give this a try? 你可以试试看吗?

You have to: 你必须:

  1. Start server in debug mode (when it start's dt_socket port is printed) 以调试模式启动服务器(打印启动的dt_socket端口时)
  2. Attach debugger Debug -> Attach Debugger... 附加调试器Debug->附加调试器...
  3. Set breakpoint 设定断点
  4. 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. @PostConstruct在部署期间被调用,因此您提供的步骤顺序不正确,因为在附加到调试器之前会调用代码。

Did you try this with eclipse? 您是否用Eclipse尝试过? As I remember, I had no problem in debugging the @PostConstruct method in eclipse. 我记得,在Eclipse中调试@PostConstruct方法没有问题。

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... 更多值得一提的是:-只要您的应用程序在服务器上存在,@ Singleton bean就会存在...因此,如果要调试其@PostConstruct,我建议您打开glassfish服务器控制台,并使用来自控制台...直到此为止,@ PostConstruct不会被调用,因为bean是容器管理的...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM