简体   繁体   中英

External java program: Handle SIGTERM

I have java program (with a gui) which is running on a host. On runtime a user can add some data records. The program just works with them.

Later the system maybe shuts down or the program is just closed by SIGTERM.

Unfortunately the porgram only seems to store the data records if it is closed manually by the user with the "X".

Now i have the problem that i maybe lose some data if the program is closed by SIGTERM. Unfortunately there is no contact email address to ask the author for the change.

I tried to decompile it with "jd gui" which seemed to work more or less. I thought then i just could add the signal handler and invoke the "window close" method.

But "jd gui" created code like this:

/* 110:269 */       if ((??? = Thread.currentThread().getContextClassLoader()) != null) {
/* 111:270 */         return ???;

And i also get many other errors if i try to compile the source.

I think this is because the jar file is obfuscated by some tool. Unfortunately the decompiled code doesn't work and i am not able to recompile the file with the JFrame.

Long story short: Is it possible to write a "wrapper program" which just handles SIGTERM and then invokes the JFrame "close method" (or how it is called) of the main frame (which is the only JFrame)?

I just do not know how to invoke such a method of an external running java program.

Thank you very much.

Best regards Kevin

Try to deobfuscate the application. Have a look here (2009) - Tool to deobfuscate Java codes .

Maybe it is possible to resolve the source so that you are able to diggin deeper into the source and compile it.

Otherwise it is quite complicated to hook into a Swing based ui event queue from outside a wrapper application.

Maybe you can decompile the main class and replace its main method with your own and add a shutdownhook see: Useful example of a shutdown hook in Java? which calls the onClose (deobfuscated) method.

Any way, an interesting and challening question!

Create your own class with a main method which installs a shutdown hook to save before closing. then invoke the original programs main method. add this to the jar and use this class to launch the program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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