From 84ed08d9a4785f7338910e1519e7fa2fbb24a9f5 Mon Sep 17 00:00:00 2001 From: Bob Jamison Date: Thu, 3 Apr 2008 03:17:12 +0000 Subject: improve jvm search to allow an embedded jre. fix missed "public" on method (bzr r5317) --- src/bind/javabind.cpp | 78 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 21 deletions(-) (limited to 'src/bind/javabind.cpp') diff --git a/src/bind/javabind.cpp b/src/bind/javabind.cpp index 6bffe0cd7..c62981f1f 100644 --- a/src/bind/javabind.cpp +++ b/src/bind/javabind.cpp @@ -324,32 +324,73 @@ static const char *commonJavaPaths[] = NULL }; + +static String getExePath() +{ + char exeName[80]; + GetModuleFileName(NULL, exeName, 80); + char *slashPos = strrchr(exeName, '\\'); + if (slashPos) + *slashPos = '\0'; + String s = exeName; + return s; +} + + +static String checkPathUnderRoot(const String &root) +{ + for (const char **path = commonJavaPaths ; *path ; path++) + { + String jpath = root; + jpath.append(*path); + //msg("trying '%s'", jpath.c_str()); + struct stat finfo; + if (stat(jpath.c_str(), &finfo)>=0) + { + //msg("found"); + return jpath; + } + } + return ""; +} + + + static CreateVMFunc getCreateVMFunc() { bool found = false; String libname; /** - * First, look for JAVA_HOME. This will allow the user + * First, look for an embedded jre in the $INKSCAPE dir. + * This allows us to package our own JRE if we want to. + */ + String inkscapeHome = getExePath(); + inkscapeHome.append("\\jre"); + msg("INKSCAPE_HOME='%s'", inkscapeHome.c_str()); + String path = checkPathUnderRoot(inkscapeHome); + if (path.size() > 0) + { + libname = path; + found = true; + } + + /** + * Next, look for JAVA_HOME. This will allow the user * to override what's in the registry - */ - const char *envStr = getenv("JAVA_HOME"); - if (envStr) + */ + if (!found) { - String javaHome = cleanPath(envStr); - msg("JAVA_HOME='%s'", javaHome.c_str()); - for (const char **path = commonJavaPaths ; *path ; path++) + const char *envStr = getenv("JAVA_HOME"); + if (envStr) { - String jpath = javaHome; - jpath.append(*path); - //msg("trying '%s'", jpath.c_str()); - struct stat finfo; - if (stat(jpath.c_str(), &finfo)>=0) + String javaHome = cleanPath(envStr); + msg("JAVA_HOME='%s'", javaHome.c_str()); + path = checkPathUnderRoot(javaHome); + if (path.size() > 0) { - //msg("found"); - libname = jpath; + libname = path; found = true; - break; } } } @@ -416,12 +457,7 @@ static CreateVMFunc getCreateVMFunc() static void getJavaRoot(String &javaroot) { - char exeName[80]; - GetModuleFileName(NULL, exeName, 80); - char *slashPos = strrchr(exeName, '\\'); - if (slashPos) - *slashPos = '\0'; - javaroot = exeName; + javaroot = getExePath(); javaroot.append("\\"); javaroot.append(INKSCAPE_BINDDIR); javaroot.append("\\java"); -- cgit v1.2.3