[libbluray-devel] Search for libbluray.jar from common install locations

hpi1 git at videolan.org
Mon Jan 14 09:08:26 CET 2013


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Jan 14 09:42:07 2013 +0200| [f9ae6c6ce59f28cc72857c38a60915eccb336e10] | committer: hpi1

Search for libbluray.jar from common install locations

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=f9ae6c6ce59f28cc72857c38a60915eccb336e10
---

 src/libbluray/bdj/bdj.c    |   56 +++++++++++++++++++++++++++++++++++++++-----
 src/libbluray/bdj/common.h |    3 ++-
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/src/libbluray/bdj/bdj.c b/src/libbluray/bdj/bdj.c
index 3f41bd0..79908b2 100644
--- a/src/libbluray/bdj/bdj.c
+++ b/src/libbluray/bdj/bdj.c
@@ -29,9 +29,11 @@
 #include "bdj_util.h"
 #include "common.h"
 #include "libbluray/register.h"
+#include "file/file.h"
 #include "file/dl.h"
 #include "util/strutl.h"
 #include "util/macro.h"
+#include "util/logging.h"
 #include "libbluray/bdnav/bdid_parse.h"
 #include "libbluray/bdj/native/register_native.h"
 
@@ -39,6 +41,11 @@
 #include <stdlib.h>
 #include <string.h>
 
+// stat
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
 typedef jint (JNICALL * fptr_JNI_CreateJavaVM) (JavaVM **pvm, void **penv,void *args);
 
 static void *_load_jvm(void)
@@ -64,6 +71,48 @@ static void *_load_jvm(void)
     return dl_dlopen(path, NULL);
 }
 
+static const char *_find_libbluray_jar(void)
+{
+    // pre-defined search paths for libbluray.jar
+    static const char * const jar_paths[] = {
+#ifdef WIN32
+        "" BDJ_JAR_FILE,
+#else
+        "/usr/lib/libbluray/" BDJ_JARFILE,
+        "/usr/share/libbluray/" BDJ_JARFILE,
+#endif
+    };
+
+    static const char *classpath = NULL;
+
+    struct stat sb;
+    unsigned i;
+
+    // check if overriding the classpath
+    if (!classpath) {
+        classpath = getenv("LIBBLURAY_CP");
+    }
+    if (classpath) {
+        return classpath;
+    }
+
+    BD_DEBUG(DBG_BDJ, "LIBBLURAY_CP not set, searching for "BDJ_JARFILE" ...\n");
+
+    // check pre-defined directories
+    for (i = 0; i < sizeof(jar_paths) / sizeof(jar_paths[0]); i++) {
+        BD_DEBUG(DBG_BDJ, "Checking %s ...\n", jar_paths[i]);
+        if (!stat(jar_paths[i], &sb)) {
+            classpath = jar_paths[i];
+            BD_DEBUG(DBG_BDJ, "using %s\n", classpath);
+            return classpath;
+        }
+    }
+
+    classpath = BDJ_CLASSPATH;
+    BD_DEBUG(DBG_BDJ | DBG_CRIT, BDJ_JARFILE" not found.\n");
+    return classpath;
+}
+
 static int _bdj_init(BDJAVA *bdjava, JNIEnv *env)
 {
     if (!bdj_register_native_methods(env)) {
@@ -123,14 +172,9 @@ BDJAVA* bdj_open(const char *path,
 
     JavaVMInitArgs args;
 
-    // check if overriding the classpath
-    const char* classpath = getenv("LIBBLURAY_CP");
-    if (classpath == NULL)
-        classpath = BDJ_CLASSPATH;
-
     // determine classpath
     //char* classpath_opt = str_printf("-Djava.class.path=%s", classpath);
-    char* classpath_opt = str_printf("-Xbootclasspath/a:%s", classpath);
+    char* classpath_opt = str_printf("-Xbootclasspath/a:%s", _find_libbluray_jar());
 
     // determine bluray.vfs.root
     char* vfs_opt;
diff --git a/src/libbluray/bdj/common.h b/src/libbluray/bdj/common.h
index 3efbc5d..5b1e48a 100644
--- a/src/libbluray/bdj/common.h
+++ b/src/libbluray/bdj/common.h
@@ -20,7 +20,8 @@
 #ifndef BDJ_COMMON_H_
 #define BDJ_COMMON_H_
 
-#define BDJ_CLASSPATH "libbluray.jar"
+#define BDJ_JARFILE   "libbluray.jar"
+#define BDJ_CLASSPATH BDJ_JARFILE
 #define BDJ_BDJO_PATH "/BDMV/BDJO"
 #define BDJ_JAR_PATH "/BDMV/JAR"
 



More information about the libbluray-devel mailing list