简体   繁体   English

如何在Jetty源代码中进行调试?

[英]How to debug in Jetty source code?

I am assigned a project in which we attempt to push content from a Jetty server to one or more connected clients, using the SPDY protocol. 我分配了一个项目,我们尝试使用SPDY协议将内容从Jetty服务器推送到一个或多个连接的客户端。 Changes to the current pushing strategy and handlers are required, so I want to change the server's implementation and be able to debug the newly inserted code. 需要更改当前的推送策略和处理程序,因此我想更改服务器的实现并能够调试新插入的代码。 I downloaded Jetty's source code from GitHub, and can use the mvn clean install command to generate a distribution in jetty-distribution/target/distribution. 我从GitHub下载了Jetty的源代码,可以使用mvn clean install命令在jetty-distribution / target / distribution中生成一个发行版。

To write my own server handlers en strategies, I loaded all Maven projects in NetBeans, and everything can be build from the top project down. 为了编写自己的服务器处理程序,我在NetBeans中加载了所有Maven项目,并且可以从顶部项目开始构建所有内容。 I defined my own handlers, and by passing the right arguments in the project Jetty-Start (jetty home and base) and using the right XML configurations, I can start the server in debug mode from within Java. 我定义了自己的处理程序,并通过在项目Jetty-Start (jetty主页和基础)中传递正确的参数并使用正确的XML配置,可以从Java内部以调试模式启动服务器。 I can the debug the main class, but in the main, Jetty is executed in another JVM: 我可以调试主类,但是在主要方面,Jetty是在另一个JVM中执行的:

// execute Jetty in another JVM
if (args.isExec())
{
    CommandLineBuilder cmd = args.getMainArgs(baseHome,true);
    cmd.debug();
    ProcessBuilder pbuilder = new ProcessBuilder(cmd.getArgs());
    StartLog.endStartLog();
    final Process process = pbuilder.start();
    Runtime.getRuntime().addShutdownHook(new Thread()
    {
        @Override
        public void run()
        {
            StartLog.debug("Destroying " + process);
            process.destroy();
        }
    });

    copyInThread(process.getErrorStream(),System.err);
    copyInThread(process.getInputStream(),System.out);
    copyInThread(System.in,process.getOutputStream());
    process.waitFor();
    System.exit(0); // exit JVM when child process ends.
    return;
}

When accessing the server through the browser, no breakpoint in the server's code is ever triggered. 通过浏览器访问服务器时,不会触发服务器代码中的断点。 I really need to be able to understand the flow from the request handlers to the pushing strategy, so how can I fully debug the server's implementation? 我真的需要能够理解从请求处理程序到推送策略的流程,那么如何完全调试服务器的实现?

You can add some parameters into your JVM :Run jetty with this 您可以在JVM中添加一些参数:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4000

than run remote and debug with this 比远程运行和调试与此

-Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4000

Hope it will helps 希望这会有所帮助

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

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