static HINSTANCE loadJVMLibrary(void) { HINSTANCE h1, h2; char msvcdll[MAX_PATH]; char javadll[MAX_PATH]; GetPublicJREHome(msvcdll, MAX_PATH); strcpy(javadll, msvcdll); strncat(msvcdll, "\\bin\\msvcr100.dll", MAX_PATH - strlen(msvcdll)); msvcdll[MAX_PATH - 1] = '\0'; strncat(javadll, "\\bin\\client\\jvm.dll", MAX_PATH - strlen(javadll)); javadll[MAX_PATH - 1] = '\0'; h1 = LoadLibrary(msvcdll); if (h1 == NULL) { // Не удается загрузить библиотеку msvcr71.dll fprintf(stderr, "Can't load library msvcr71.dll\n"); exit(1); } h2 = LoadLibrary(javadll); if (h2 == NULL) { // Не удается загрузить библиотеку jvm.dll fprintf(stderr, "Can't load library jvm.dll\n"); exit(1); } return h2; }
/* * Find path to JRE based on .exe's location or registry settings. */ jboolean GetJREPath(char *path, jint pathsize) { char javadll[MAXPATHLEN]; struct stat s; if (GetApplicationHome(path, pathsize)) { /* Is JRE co-located with the application? */ sprintf(javadll, "%s\\bin\\" JAVA_DLL, path); if (stat(javadll, &s) == 0) { goto found; } /* Does this app ship a private JRE in <apphome>\jre directory? */ sprintf(javadll, "%s\\jre\\bin\\" JAVA_DLL, path); if (stat(javadll, &s) == 0) { strcat(path, "\\jre"); goto found; } } /* Look for a public JRE on this machine. */ if (GetPublicJREHome(path, pathsize)) { goto found; } fprintf(stderr, "Error: could not find " JAVA_DLL "\n"); return JNI_FALSE; found: if (_launcher_debug) printf("JRE path is %s\n", path); return JNI_TRUE; }
/* * Find path to JRE based on .exe's location or registry settings. */ jboolean GetJREPath(char *path, jint pathsize) { char javadll[MAXPATHLEN]; struct stat s; if (GetApplicationHome(path, pathsize)) { /* Is JRE co-located with the application? */ JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path); if (stat(javadll, &s) == 0) { JLI_TraceLauncher("JRE path is %s\n", path); return JNI_TRUE; } /* Does this app ship a private JRE in <apphome>\jre directory? */ JLI_Snprintf(javadll, sizeof (javadll), "%s\\jre\\bin\\" JAVA_DLL, path); if (stat(javadll, &s) == 0) { JLI_StrCat(path, "\\jre"); JLI_TraceLauncher("JRE path is %s\n", path); return JNI_TRUE; } } /* Look for a public JRE on this machine. */ if (GetPublicJREHome(path, pathsize)) { JLI_TraceLauncher("JRE path is %s\n", path); return JNI_TRUE; } JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL); return JNI_FALSE; }
jboolean GetJREPath(char *path, jint pathsize) { char javadll[MAXPATHLEN]; struct stat s; if (GetApplicationHome(path, pathsize)) { // Is JRE co-located with the application? sprintf_s(javadll, sizeof javadll, "%s\\bin\\"JAVA_DLL, path); if (stat(javadll, &s) == 0) { goto found; } // Does this app ship a private JRE in <apphome>\jre directory? sprintf_s(javadll, sizeof javadll, "%s\\jre\\bin\\" JAVA_DLL, path); if (stat(javadll, &s) == 0) { strcat_s(path, pathsize, "\\jre"); goto found; } } // Look for a public JRE on this machine. if (GetPublicJREHome(path, pathsize)) { goto found; } return JNI_FALSE; found: return JNI_TRUE; }
/* * Find path to JRE based on .exe's location or registry settings. */ jboolean GetJREPath(char *path, jint pathsize) { char javadll[MAXPATHLEN]; struct stat s; if (GetApplicationHome(path, pathsize)) { /* Is JRE co-located with the application? */ JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path); if (stat(javadll, &s) == 0) { JLI_TraceLauncher("JRE path is %s\n", path); return JNI_TRUE; } /* ensure storage for path + \jre + NULL */ if ((JLI_StrLen(path) + 4 + 1) > (size_t) pathsize) { JLI_TraceLauncher("Insufficient space to store JRE path\n"); return JNI_FALSE; } /* Does this app ship a private JRE in <apphome>\jre directory? */ JLI_Snprintf(javadll, sizeof (javadll), "%s\\jre\\bin\\" JAVA_DLL, path); if (stat(javadll, &s) == 0) { JLI_StrCat(path, "\\jre"); JLI_TraceLauncher("JRE path is %s\n", path); return JNI_TRUE; } } /* Try getting path to JRE from path to JLI.DLL */ if (GetApplicationHomeFromDll(path, pathsize)) { JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path); if (stat(javadll, &s) == 0) { JLI_TraceLauncher("JRE path is %s\n", path); return JNI_TRUE; } } #ifdef USE_REGISTRY_LOOKUP /* Lookup public JRE using Windows registry. */ if (GetPublicJREHome(path, pathsize)) { JLI_TraceLauncher("JRE path is %s\n", path); return JNI_TRUE; } #endif JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL); return JNI_FALSE; }
/* * Find path to JRE based on .exe's location or registry settings. */ jboolean GetJREPath(char *path, jint pathsize) { char javadll[MAXPATHLEN]; struct stat s; // // if (GetApplicationHome(path, pathsize)) { // /* Is JRE co-located with the application? */ // sprintf(javadll, "%s\\bin\\" JAVA_DLL, path); // if (stat(javadll, &s) == 0) { // goto found; // } // /* Does this app ship a private JRE in <apphome>\jre directory? */ // sprintf(javadll, "%s\\jre\\bin\\" JAVA_DLL, path); // if (stat(javadll, &s) == 0) { // strcat(path, "\\jre"); // goto found; // } // } /* Look for a public JRE on this machine. */ if (GetPublicJREHome(path, pathsize)) goto found; fprintf(stderr, "Error: could not find " JAVA_DLL "\n"); return JNI_FALSE; found: { // trick into thinking that the jre/bin path is in the PATH char *oldPath = getenv("PATH"); char *newPath; if(oldPath != NULL) { newPath = MemAlloc(strlen(oldPath) + strlen(path) + 6 + 6 + 1); // PATH=<new>\bin;<old> sprintf(newPath, "PATH=%s\\bin;%s", path, oldPath); } else { newPath = MemAlloc(strlen(path) + 6 + 1); sprintf(newPath, "PATH=%s\\bin", path); } _putenv(newPath); free(newPath); } return JNI_TRUE; }