ProcessBuilder调试
我创建了一个可执行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,所以我设法让它发挥作用。不幸的是,我找不到为此使用的示例项目,因此我将尽力解释。
考虑上面的这一行 -
我需要做的就是添加 Xdebug 作为参数 -
然后我在 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 -
All I needed to do was add Xdebug as a parameter to this -
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!
在Eclipse中调试jar包的方法:
在这种情况下,jar 文件和您的项目在同一进程中运行。
但是当你运行 jar 文件时
ProcessBuilder,jar文件运行在独立于你的项目的另一个进程中,当然也独立于eclipse,即jar文件按照你在命令行中输入“java -jar jarfile”的方式运行。
the method of debug jar package in Eclipse:
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.