[英]How to handle the output of .jar file(which does not have any exit code with System.exit() ) in a batch file if the jar file throws an exception?
I have an existing very large number of .jar files and I'm supposed to catch if any exception arises and then need to call a different .jar file. 我已经有大量的.jar文件,如果有任何异常发生,我就应该捕获,然后需要调用其他.jar文件。 This could have been done by catching the exception and setting an exit code and then checking in the batch file but there's a large number of .jar files.
可以通过捕获异常并设置退出代码,然后检入批处理文件来完成此操作,但是存在大量的.jar文件。
JAR file looks this way: JAR文件如下所示:
public class FileProcessor{
public static void main(String[] args){
try{
}catch(Exception ex){
//if error occurs, a mail gets send
}
}
}
Is there any alternative way without changing the .jar file and just work on the batch file. 有没有其他方法可以更改.jar文件而仅在批处理文件上工作?
I'm confident there isn't a trivial way to do this from a batch file. 我相信没有简单的方法可以从批处理文件中执行此操作。
However there may be a way to do it without editing the Java. 但是,可能有一种无需编辑Java即可实现的方法。 Instead of calling into the jar directly from a batch file, you could call it from another Java application and use reflection to override the methods that have catch blocks that you need to set an exit code for.
您可以从另一个Java应用程序中调用它,而不是直接从批处理文件调用jar,并使用反射来覆盖具有捕获块的方法,而这些捕获块需要为其设置退出代码。
This is probably more work than your suggestion and you may be better off editing the existing Java to behave as you want it to with exit codes. 这可能比您的建议还要多,而且最好编辑现有的Java以使其符合退出代码的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.