< prev index next >
modules/jdk.packager/src/main/native/javapackager/win/javapackager.cpp
Print this page
@@ -407,13 +407,11 @@
#endif
delete nv;
}
}
}
-
}
-
}
}
RegCloseKey(hKey);
}
@@ -441,10 +439,26 @@
else {
return false;
}
}
+#define TRAILING_PATHSEPARATOR '\\'
+
+std::wstring ExtractFilePath(std::wstring Path) {
+ std::wstring result;
+ size_t slash = Path.find_last_of(TRAILING_PATHSEPARATOR);
+ if (slash != std::wstring::npos)
+ result = Path.substr(0, slash);
+ return result;
+}
+
+std::wstring GetCurrentExecutableName() {
+ TCHAR FileName[MAX_PATH];
+ GetModuleFileName(NULL, FileName, MAX_PATH);
+ return FileName;
+}
+
int wmain(int argc, wchar_t* argv[]) {
wchar_t buf[MAX_PATH];
GetModuleFileName(NULL, buf, MAX_PATH);
std::wstring javafxhome = buf;
@@ -464,22 +478,24 @@
javacmd = L"";
javahome = L"";
}
}
else {
- javacmd = L"";
+ std::wstring exe = GetCurrentExecutableName();
+ javacmd = ExtractFilePath(exe) + L"\\java.exe";
}
if (javacmd.length() <= 0) {
JavaVersion * jv2 = GetMaxVersion(HKEY_LOCAL_MACHINE, "SOFTWARE\\JavaSoft\\Java Development Kit");
if (jv2 != NULL) {
javacmd = jv2->path;
javahome = jv2->home;
}
- else
+ else {
javacmd = L"java.exe";
}
+ }
std::wstring cmd = L"\"" + javacmd + L"\"";
if (javahome.length() > 0) {
SetEnvironmentVariable(L"JAVA_HOME", javahome.c_str());
}
< prev index next >