通过JNI部署JRE:jvm.dll并非设计用于在Windows或[......]上运行 [英] Deploying JRE via JNI: jvm.dll not designed to run on Windows or [......]

查看:80
本文介绍了通过JNI部署JRE:jvm.dll并非设计用于在Windows或[......]上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在创建一个Win32应用程序,该应用程序将Java Runtime Environment(JRE)打包为资源.应用程序将资源提取到磁盘并解压缩.现在,我想使用此JRE以便通过调用API运行Java程序.一旦我更改程序以指向提取的JRE的jvm.dll而不是已安装的JRE(这就是我复制的内容),我就会收到此错误:

So I'm creating a Win32 application that packages the Java Runtime Environment (JRE) as a resource. The application extracts the resource to the disk and unzips it. Now, I would like to use this JRE in order to run a Java program using the invocation API. As soon as I changed to program to point to the extracted JRE's jvm.dll instead of the installed JRE (which is what I copied), I received this error:

< jre-path> \ jre1.8.0_31 \ bin \ server \ jvm.dll并非旨在在Windows上运行,或者包含错误.请尝试使用原始安装媒体再次安装程序,或与系统管理员或软件供应商联系以获取支持.错误状态0x000012f

<jre-path>\jre1.8.0_31\bin\server\jvm.dll is either not designed to run on Windows or it contains an error. Try installing the program again using the original installation media or contact your system administrator or the software vendor for support. Error status 0x000012f

我希望与此问题相关的是记录此错误以及引起此错误的原因.并且,如果可能的话,找到一个解决方案,以便我可以引用提取的JRE.

What I am hoping to do with this question is to document this error as well as what caused it. And if possible, find a solution so I can reference the extracted JRE.

让我详细说明一下我的环境.首先,我正在运行Windows 10 Tech Preview.我的OS,我的程序以及从安装中复制的JRE都是64位的.另外,当我将程序指向已安装的JRE时,它运行良好,问题仅在于复制的JRE.

Let me give some specifics to my environment. First of all I'm running Windows 10 Tech Preview. My OS, my program, and the JRE I copied from the installation are all 64-bit. Also, when I had my program point to the installed JRE, it worked fine, the problem is only with the copied JRE.

还有一些代码可供我参考:

And some code for reference of what I'm doing:

typedef jint (JNICALL *CreateJVMFunc)(JavaVM **pvm, void **penv, void *args);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    //For brevity I am omitting the extraction/unzipping.
    //I am using libzip to do the unzipping which uses zlib
    //for dealing with the compression/decrompression.
    //Likewise, I am also omitting the error checking for brevity.

    //Assume at this point the JRE folder exists in the same location
    //as this program's executable file.  I am accessing the jvm.dll
    //using a relative file path.

    //Load the Java virtual machine inside of the packaged JRE.
    //This is where that error occurs.
    //LoadLibrary is necessary because I must connect to the DLL after
    //it has been unpacked.
    HMODULE jvmDll = LoadLibrary(_T("jre1.8.0_31\\bin\\server\\jvm.dll"));
    CreateJVMFunc CreateJVM = (CreateJVMFunc)GetProcAddress(jvmDll, "JNI_CreateJavaVM");

    //Start the Java virtual machine.
    JavaVM *jvm;
    JNIEnv *env;
    JavaVMInitArgs vmArgs;
    JavaVMOption *options = new JavaVMOption[1];
    options[0].optionString = "-Djava.class.path=C:/Users/Nicholas/Documents/Programming Projects/Java Projects/JVM Launcher Test/JVM Launcher Test.jar"
    vmArgs.version = JNI_VERSION_1_8;
    vmArgs.nOptions = 1;
    vmArgs.options = options;
    vmArgs.ignoreUnrecognized = false;

    int retVal = CreateJVM(&jvm, (void**)&env, &vmArgs);
    delete[] options;

    //Instantiate the program.
    jclass mainClass = env->FindClass("jvmlauncher/test/Application");
    jmethodID mainMethod = env->GetStaticMethodID(mainClass, "main", "([Ljava/lang/String;)V");
    env->CallStaticVoidMethod(mainClass, mainMethod, NULL);

    //Cleanup.
    jvm->DestroyJavaVM();
    FreeLibrary(jvmDll);
    return 0;
}

所以我想有一些我想找到答案的问题.

So I suppose there are a few questions I would like to find answers for.

  • 究竟是什么触发了错误消息?此错误并非我的应用程序所独有,因此该错误存在哪些文档?

  • What exactly triggers the error message? This error is not unique to my application, so what documentation exists for that error?

为什么复制的JRE(已安装的JRE的精确副本)不能按我预期的那样工作?

Why is the copied JRE (which is an exact copy of the installed one) not working as I expected?

如何纠正这种情况,以便可以使用此未打包的JRE?

How can I correct the situation so I can use this unpacked JRE?

推荐答案

究竟是什么触发了错误消息?此错误不是我的应用程序所独有的,那么该错误存在哪些文档?

What exactly triggers the error message? This error is not unique to my application, so what documentation exists for that error?

错误消息是正确的.我的自定义安装出现了问题.从可执行文件中提取文件时,显然文件丢失了数据. 在实际复制了当前安装的JRE之后,一切正常!

The error message is right. Something was wrong with my custom installation. Apparently the files lost data when extracted from the executable file. After literally copying in the currently installed JRE, everything works!

为什么复制的JRE(这是已安装的JRE的精确副本)不能按我预期的那样工作?

Why is the copied JRE (which is an exact copy of the installed one) not working as I expected?

因为它不是精确"副本.

Because it is not an "exact" copy.

如何纠正这种情况,以便可以使用此未打包的JRE?

How can I correct the situation so I can use this unpacked JRE?

这不再是问题,因为这是我的错.提取未正确完成.

This is no longer an issue because it was a fault on my end. The extraction wasn't done correctly.

这篇关于通过JNI部署JRE:jvm.dll并非设计用于在Windows或[......]上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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