简体   繁体   English

处理从批处理文件运行Java的错误

[英]Handle errors running Java from batch file

I've got a (fairly typical) setup at the moment of launching my Java application through a batch file calling the jar file with appropriate parameters, which most of the time works absolutely fine. 我通过一个批处理文件启动我的Java应用程序时,我有一个(相当典型的)设置,调用带有适当参数的jar文件,大多数时候它都可以正常工作。 However, I'd like to be able to deal with any errors that might occur nicely. 但是,我希望能够处理可能发生的任何错误。

At the moment I've got something like 目前我有类似的东西

java -Xms1024m -Xmx1024m -jar Quelea.jar
IF NOT (%ERRORLEVEL% == 0) cscript MessageBox.vbs "Application failed to start."

The last line is basically the first answer on this question . 最后一行基本上是这个问题的第一个答案。

I'd like something a bit more fully featured though, even if it's a case of capturing the output from launching the process and then dumping it in the message box (ok, it's not pretty but it shouldn't appear to start with and when it does appear that then gives me some immediate debugging information without having to ask the user to grab out log files!) Or are there any other approaches that people use in similar situations? 我想要一些更全功能的东西,即使它是从启动过程捕获输出然后将其转储到消息框中的情况(好吧,它不是很漂亮,但它似乎不应该开始时和它似乎然后给了我一些即时的调试信息,而不必要求用户抓取日志文件!)或者是否有人在类似情况下使用的其他方法?

I'm not talking about exceptions thrown in my code (which I deal with once the application starts) I'm talking about hard errors that prevent it starting such as using an old JRE version, not having enough memory to reserve for heap, that sort of thing. 我不是在谈论我的代码中抛出的异常(我在应用程序启动时处理的异常)我正在谈论阻止它启动的硬错误,例如使用旧的JRE版本,没有足够的内存来保留堆,那类的东西。

I suggest using a Java executable wrapper. 我建议使用Java可执行包装器。 I like the following, but there are others. 我喜欢以下,但还有其他人。

http://launch4j.sourceforge.net/ http://launch4j.sourceforge.net/

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

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