ProcessBuilder调试

发布于 2025-01-04 05:11:13 字数 518 浏览 1 评论 0原文

我创建了一个可执行 jar 并使用另一个 java 程序的进程构建器执行它。这是我的代码 -

public class SomeClass {
public static void main(String[] args) {
    Process p = null;
    ProcessBuilder pb = new ProcessBuilder("java", "-jar", "src.jar");
    pb.directory(new File("/Users/vivek/servers/azkaban-0.10/TestApp/src"));
    try {
        p = pb.start();
    } catch(Exception ex) {
        ex.printStackTrace();
    }
}

}

我现在正在尝试从 eclipse 调试 src.jar。我在调试配置中提供了项目 src 作为外部项目,但它仍然没有遇到任何断点。有没有办法为这样的事情设置调试环境?

I created an executable jar and executed it using process builder from another java program. Here's my code -

public class SomeClass {
public static void main(String[] args) {
    Process p = null;
    ProcessBuilder pb = new ProcessBuilder("java", "-jar", "src.jar");
    pb.directory(new File("/Users/vivek/servers/azkaban-0.10/TestApp/src"));
    try {
        p = pb.start();
    } catch(Exception ex) {
        ex.printStackTrace();
    }
}

}

I'm trying to now debug the src.jar from eclipse. I provided the project src as external project in my debug configuration, but it still never hits any of my break points. Is there a way to set up a debug environment for something like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烙印 2025-01-11 05:11:13

好的,所以我设法让它发挥作用。不幸的是,我找不到为此使用的示例项目,因此我将尽力解释。
考虑上面的这一行 -

ProcessBuilder pb = new ProcessBuilder("java", "-jar", "src.jar");

我需要做的就是添加 Xdebug 作为参数 -

ProcessBuilder pb = new ProcessBuilder("java", "-jar", "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005", "src.jar");

然后我在 eclipse 中创建了一个调试环境,将端口设置为 5005 并在 jar 的源代码中设置了一些断点,它起作用了!

Ok, so I managed to get this to work. Unfortunately, I cannot find the sample project I used for this, so I'll try to explain the best I can.
Consider this line from above -

ProcessBuilder pb = new ProcessBuilder("java", "-jar", "src.jar");

All I needed to do was add Xdebug as a parameter to this -

ProcessBuilder pb = new ProcessBuilder("java", "-jar", "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005", "src.jar");

Then I created a debug environment in eclipse, set the port as 5005 and set a few breakpoints in the jar's source code and it worked!

眼藏柔 2025-01-11 05:11:13

在Eclipse中调试jar包的方法:

  1. 在项目的Referenced Lib中选择jar。
  2. 在java源附件中您可以指定源代码的位置。
  3. 从您的项目中调用一些 jar 文件类。
  4. 添加断点并调试您的项目。

在这种情况下,jar 文件和您的项目在同一进程中运行。

但是当你运行 jar 文件时
ProcessBuilder,jar文件运行在独立于你的项目的另一个进程中,当然也独立于eclipse,即jar文件按照你在命令行中输入“java -jar jarfile”的方式运行。

the method of debug jar package in Eclipse:

  1. Select the jar in Referenced Lib of the project.
  2. In java source attachment you can specify the location of the source code.
  3. Invoke some classes of jar file from your project.
  4. Add break points and debug your project.

The jar file and your project is running in the same process in this case.

But when you run the jar file by
ProcessBuilder, the jar file is running in another process independent of your project, of course independent of eclipse, i.e. the jar file is running the way in which you enter 'java -jar jarfile' in the command line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文