如何将JNI挂钩添加到Spring Boot生成的一个jar中 [英] How to add JNI hooks to one jar generated by Spring Boot

查看:880
本文介绍了如何将JNI挂钩添加到Spring Boot生成的一个jar中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Boot gradle插件( org.springframework.boot )来生成一个jar。当我运行 java -jar app.jar 时,它运行良好 - 完全符合预期。但是,此应用程序应该通过JNI使用Apache Commons Daemon作为守护程序运行。这个应用程序的早期版本是建立在自制框架之上的,我在开始关闭方法我可以在守护进程配置中指定的主类。

I am using Spring Boot gradle plugin (org.springframework.boot) to generate the "one" jar. It works well when I run java -jar app.jar - does exactly what's expected. However, this application should be running as a daemon using Apache Commons Daemon via JNI. Previous version of this app was built on top of a home-made framework, I had start and shutdown methods in the main class I could specify in the daemon config.

我看到Main-Class变为 org.springframework.boot.loader.JarLauncher ,它没有 start shutdown 在其中任何地方实现的方法,或者它的超级课程。有一个启动方法,但我认为这只能用于运行带有 java -jar 的jar。

I saw that Main-Class becomes org.springframework.boot.loader.JarLauncher, which does not have a start and shutdown methods implemented anywhere in it or it's superclasses. There is a launch method, but I think that can only work for running the jar with java -jar.

这是gradle插件生成的清单文件(编辑)和反编译的jar的内容:

Here is the manifest file (redacted) generated by the gradle plugin and contents of the decompiled one jar:

Manifest-Version: 1.0
Start-Class: com.company.myapp.Application
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Version: 1.5.6.RELEASE
Main-Class: org.springframework.boot.loader.JarLauncher

< img src =https://i.stack.imgur.com/eAGnB.pngalt =在此输入图像说明>

我的问题然后是:我可以配置这个gradle插件来添加JNI钩子方法,以便它们正确运行我的应用程序的主类吗?我知道Gradle有一个Shadow插件来制作uberjar,我也可以放弃创建超级jar并分发到 lib / 目录(它是桌面应用程序)。但是,如果Spring Boot开发人员考虑过它并且有办法做到这一点,我宁愿使用它。

My question then is: can I configure this gradle plugin to add JNI hooks methods so that they run my app's main class correctly? I know there is a Shadow plugin for Gradle to make the "uber" jar, and I can also forgo creating the "uber" jar and distribute in a lib/ directory (it's a desktop application). However, if Spring Boot developers thought about it and there is a way to do this, I'd rather use that.

推荐答案

所以我使用 StartMode = Java 而不是 jvm ,它似乎工作正常。唯一的问题是我不认为Spring Boot正在关闭,但我现在可以忍受。

So I am using StartMode=Java instead of jvm and it seems to work alright. The only problem is I don't think Spring Boot is gracefully shutting down but I can live with that for now.

MyApp.exe //IS//MyApp --Install="C:\appData\Programs\MyApp\MyApp.exe" ^
 --Startup=auto --StartMode=Java ^
 --JavaHome="C:\appData\Programs\Java" ^
 --Classpath="C:\appData\Programs\MyApp\MyApp.jar" ^
 --StartClass="org.springframework.boot.loader.JarLauncher" ^
 --ServiceUser="MyAppUser --ServicePassword="xxxxxx" ^
 --LogPath="C:\appData\Programs\MyApp\logs" ^
 --StartPath="C:\appData\Data\MyApp" ^
 --StopTimeout=30

我重命名exe文件以匹配我的应用程序名称MyApp,我在Windows Server上使用64位exe和64位JVM。我得到了系统中的Windows事件查看器中的服务用户发生了一些奇怪的DCOM错误,但重新启动并确保我的服务用户拥有权限s文件夹修好了。

I renamed the exe files to match my app name "MyApp" and I used the 64-bit exe with a 64-bit JVM on Windows Server. I got some weird DCOM errors with the Service User in Windows Event Viewer under System, but a few restarts and making sure my service user had permissions on this folder fixed it up.

这篇关于如何将JNI挂钩添加到Spring Boot生成的一个jar中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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