简体   繁体   English

如果jar文件引发异常,如何在批处理文件中处理.jar文件(System.exit()没有任何退出代码)的输出?

[英]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.

相关问题 如果jar文件引发异常,如何处理批处理文件中.jar文件的输出? - How to handle the output of .jar file in a batch file if the jar file throws an exception? System.exit在“ sbt运行”中工作,但不在.jar中 - System.exit working in “sbt run” but not in .jar 如何创建批处理文件以运行系统任何位置的jar文件 - How to create a batch file to run a jar file that is in any location of the system 当运行jar文件失败时,java不会退回以提示 - java does not exit back to prompt when running jar file fails 套接字发送的文件大小为0,除非我使用System.exit(0),否则访问被阻止,如何避免这种情况? - file size sent by socket is 0 and access blocked unless I use System.exit(0), how to avoid this? 如何读取没有清单的war / jar文件 - How to read a war/jar file which does not have manifest 当SecurityManager.checkExit抛出异常时,System.exit(0)不会阻止最终被调用 - System.exit(0) does not prevent finally being called when have a SecurityManager.checkExit throw an exception 黄瓜测试用例中如何处理system.exit - How to handle system.exit in the cucumber test case Spring批处理中的System.exit(1) - System.exit(1) from Spring batch 如何运行包含对批处理文件调用的 jar 文件? - How run a jar file which contains a call to a batch file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM