在Java中启动JAR文件会在lib加载时挂起 [英] Launching a JAR file in Java suspends on lib loading

查看:524
本文介绍了在Java中启动JAR文件会在lib加载时挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试在Java应用程序中启用命令行处理,以便在命令行参数传递到应用程序时自动执行某些事件。



有两个正在执行的应用程序,管理报告。我们的想法是允许管理软件使用命令行参数启动报告软件,然后命令行参数将自动生成报告并将结果存储在文件系统中。看起来很简单。



我已经设法拼凑代码来实现这一点(传递给报告的命令行参数Java应用程序并不总是相同的因此这不能通过脚本完成。)它看起来像这样:



Hi all,

I'm trying to enable command-line processing within a Java application to automate certain events whenever command-line arguments as passed into the application.

There are two applications which are executing, management and reports. The idea is to allow the management software to launch the reports software with command-line arguments, which will then automatically generate a report and store the result on the file-system. Seems simple enough.

I've managed to piece together code to accomplish this (the command-line arguments which are passed into the reports Java application are not always the same, thus this cannot be accomplish via script.) It looks something like this:

ProcessBuilder processBuilder = new ProcessBuilder(
 "/path/to/javaw",
 "-Djava-library.path=.",
 "-jar",
 "/path/to/jar/file"
);
processBuilder.directory("/path/to/jar/directory");
processBuilder.command().add("/auto");
processBuilder.command().add("someParameter");
processBuilder.start();





这很好用,启动报告Java应用程序并运行命令行处理算法。



然而,我发现报告Java应用程序暂停,直到启动管理Java应用程序关闭。只有这样,报告Java应用程序才能继续处理它。



我相信它与加载库依赖关系有关。在收集了大量的调试语句后,我逐渐意识到报告应用程序在加载Jasper Reports库时会暂停。应用程序冻结,当管理关闭时,库已加载并继续。



有人能想到这可能会出现这种情况的原因吗?我可以确认使用javaw直接启动报告JAR文件工作正常,并创建报告。只是在启动这种方法时,应用程序才会挂起,直到管理javaw进程退出。



提前感谢!



This works fine, launching the reports Java application and running through the command-line processing algorithm.

What I'm finding, however, is that the reports Java application is suspended until the launching management Java application is shutdown. Only then does the reports Java application continue processing as it should.

I believe it has something to do with loading library dependencies. After putting in an enormous collection of debug statements, I've come to realise that the reports application suspends when it comes to loading a Jasper Reports library. The application freezes, and when management is shutdown the library is loaded and continues.

Can anyone think of a reason why this might behave this way? I can confirm that launching the reports JAR file directly using javaw works fine, and reports are created. It's just when launching through this methodology that the application hangs until the management javaw process has exited.

Thanks in advance!

推荐答案

您需要排出输出流以防止挂起。查看链接以获取一些详细信息。



http://www.rgagnon.com/ javadetails / java-0014.html [ ^ ]

http://steveliles.github.io/invoking_processes_from_java.html [< a href =http://steveliles.github.io/invoking_processes_from_java.htmltarget =_ blanktitle =新窗口> ^ ]



祝你好运!
You need to drain the output streams to prevent hanging. Check the links for some detailed info.

http://www.rgagnon.com/javadetails/java-0014.html[^]
http://steveliles.github.io/invoking_processes_from_java.html[^]

Good luck!


这篇关于在Java中启动JAR文件会在lib加载时挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆