How can I deploy a mixed C++/Java (JNI) application?

前端 未结 3 398
执笔经年
执笔经年 2021-01-14 04:50

tl;dr: C++ plugin needs to call Java .jar library. How to deploy this to users without too much headache?

I\'m writing a Qt plugin for a Qt applica

3条回答
  •  旧巷少年郎
    2021-01-14 05:22

    A possible solution for Windows only.

    Build the QT plugin using the delayed DLL load feature

    See DELAYLOAD on how to do this but it is just adding /DELAYLOAD:jvm.dll and Delayimp.lib to the linker command. It means that the jvm.dll will not be loaded when the QT plugin is loaded but at the point it is required (note it does not require using LoadLibrary() and GetProcAddress()). (I don't know if there is a similar feature on Linux or Mac)

    Provide a mechanism to inform the QT plugin of what JRE to use

    This could be either a registry value, a configuration file or an environment variable specifically for the plugin (definitely not environment variables JAVA_HOME or JRE_HOME that other applications may depend on). Example environment variables:

    • DANQT_32_JRE_HOME=C:\Program Files (x86)\Java\jre7 (for 32-bit JRE)
    • DANQT_64_JRE_HOME=C:\Program Files\Java\jre7 (for 64-bit JRE)

    QT Plugin Modify its PATH

    Before the QT plugin invokes any functions dependent on the JRE it modifies its PATH environment variable by inserting, for example, %DANQT_32_JRE_HOME%\bin\server;%DANQT_32_JRE_HOME%\bin\client; at the start of the value for PATH. This means when the QT plugin performs its first action that requires the JRE it will be loaded from the inserted directories. (Different environment variables for 64-bit). As for bin\server and bin\client my understanding is that these are essentially the same but the server performs more during initialisation for runtime performance reasons.

    I am unsure of compatibility if the QT plugin was built against JRE 6 and JRE 7 was installed. If there are compatibility issues then make it a prerequisite installation requirement or, if permitted (I am unsure of legalities), ship the jvm.dll with the QT plugin.

提交回复
热议问题