Cezar Andrei has proposed merging 
lp:~zorba-coders/zorba/fread-pdf-utiljvm-module into lp:zorba/util-jvm-module.

Requested reviews:
  Chris Hillery (ceejatec)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/fread-pdf-utiljvm-module/+merge/125332

Add java.library.path property when starting the jvm
-- 
https://code.launchpad.net/~zorba-coders/zorba/fread-pdf-utiljvm-module/+merge/125332
Your team Zorba Coders is subscribed to branch lp:zorba/util-jvm-module.
=== modified file 'include/JavaVMSingleton.h'
--- include/JavaVMSingleton.h	2012-05-22 09:56:29 +0000
+++ include/JavaVMSingleton.h	2012-09-19 20:32:20 +0000
@@ -1,12 +1,12 @@
 /*
  * Copyright 2006-2008 The FLWOR Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -44,12 +44,16 @@
 
 namespace zorba { namespace jvm {
 
+#define NO_OF_JVM_OPTIONS 3
+
+
 class VMOpenException {};
 
 class UTIL_JVM_DLL_PUBLIC JavaVMSingleton
 {
 public:
-  static JavaVMSingleton* getInstance(const char* classPath);
+  //static JavaVMSingleton* getInstance(const char* classPath);
+  static JavaVMSingleton* getInstance(const char* classPath, const char* javaLibPath);
   static JavaVMSingleton* getInstance(const zorba::StaticContext* aStaticContext);
 
   virtual ~JavaVMSingleton();
@@ -57,19 +61,27 @@
   JNIEnv* getEnv();
 
 protected:
-  JavaVMSingleton(const char* classPath);
+  JavaVMSingleton(const char* classPath, const char* javaLibPath);
   JavaVMSingleton(JavaVM *jvm, JNIEnv *env) : m_vm(jvm), m_env(env) {}
   static String computeClassPath(const zorba::StaticContext* aStaticContext);
+  static String computeLibPath(const zorba::StaticContext* aStaticContext);
 
   static JavaVMSingleton* instance;
   JavaVM* m_vm;
   JNIEnv* m_env;
   JavaVMInitArgs args;
-  JavaVMOption options[2];
+  JavaVMOption options[NO_OF_JVM_OPTIONS];
+
+  char* classPathOption;
   char* awtOption;
-  char* classPathOption;
+  char* jlpOption;
 };
 
+
 }} //namespace zorba, jvm
 
 #endif // JAVA_VM_SINGLETON
+
+
+
+

=== modified file 'src/JavaVMSingleton.cpp'
--- src/JavaVMSingleton.cpp	2012-05-25 17:50:10 +0000
+++ src/JavaVMSingleton.cpp	2012-09-19 20:32:20 +0000
@@ -1,12 +1,12 @@
 /*
  * Copyright 2006-2008 The FLWOR Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,13 +32,13 @@
 namespace zorba { namespace jvm {
 JavaVMSingleton* JavaVMSingleton::instance = NULL;
 
-JavaVMSingleton::JavaVMSingleton(const char* classPath)
+JavaVMSingleton::JavaVMSingleton(const char* classPath, const char* javaLibPath)
 {
   //std::cout << "JavaVMSingleton::JavaVMSingleton classPath: " << classPath << "\n"; std::cout.flush();
 
   memset(&args, 0, sizeof(args));
   jint r;
-  jint nOptions = 2;
+  jint nOptions = NO_OF_JVM_OPTIONS;
 
   std::string classpathOption;
   std::ostringstream os;
@@ -47,15 +47,28 @@
   classPathOption = new char[classpathOption.size() + 1];
   memset(classPathOption, 0, sizeof(char) * (classpathOption.size() + 1));
   memcpy(classPathOption, classpathOption.c_str(), classpathOption.size() * sizeof(char));
+
   std::string lAwtArgStr = "-Djava.awt.headless=true";
   awtOption = new char[lAwtArgStr.size() + 1];
   memset(awtOption, 0, sizeof(char) * (lAwtArgStr.size() + 1));
   memcpy(awtOption, lAwtArgStr.c_str(), sizeof(char) * lAwtArgStr.size());
   awtOption[lAwtArgStr.size()] = 0;
+
+  //// std::string jlpStr = "-Djava.library.path=/home/cezar/dev/repo/fpdf/fpdf/build/zorba_modules/zorba_util-jvm_module/src/:/home/cezar/dev/repo/fpdf/fpdf/build/LIB_PATH/com/zorba-xquery/www/modules/";
+  // javaLibPath are only base pathes, the full path will be computed at runtime in the Java class
+  std::string jlpStr = "-Djava.library.path=" + std::string(javaLibPath);
+  jlpOption = new char[jlpStr.size() + 1];
+  memset(jlpOption, 0, sizeof(char) * (jlpStr.size() + 1));
+  memcpy(jlpOption, jlpStr.c_str(), sizeof(char) * jlpStr.size());
+  jlpOption[jlpStr.size()] = 0;
+
   options[0].optionString = classPathOption;
   options[0].extraInfo = NULL;
   options[1].optionString = awtOption;
   options[1].extraInfo = NULL;
+  options[2].optionString = jlpOption;
+  options[2].extraInfo = NULL;
+
   memset(&args, 0, sizeof(args));
   args.version  = JNI_VERSION_1_2;
   args.nOptions = nOptions;
@@ -81,7 +94,12 @@
     delete[] classPathOption;
 }
 
-JavaVMSingleton* JavaVMSingleton::getInstance(const char* classPath)
+/*JavaVMSingleton* JavaVMSingleton::getInstance(const char* classPath)
+{
+  return getInstance(classPath, "");
+}*/
+
+JavaVMSingleton* JavaVMSingleton::getInstance(const char* classPath, const char* javaLibPath)
 {
 //#ifdef WIN32
 //  // If pointer to instance of JavaVMSingleton exists (true) then return instance pointer else look for
@@ -118,19 +136,22 @@
 
     if (instance == NULL)
     {
-      instance = new JavaVMSingleton(classPath);
+      instance = new JavaVMSingleton(classPath, javaLibPath);
     }
   }
 
   return instance;
 }
 
+
+
 JavaVMSingleton* JavaVMSingleton::getInstance(const zorba::StaticContext* aStaticContext)
 {
   if (instance == NULL)
   {
     String cp = computeClassPath(aStaticContext);
-    return getInstance(cp.c_str());
+    String lp = computeLibPath(aStaticContext);
+    return getInstance(cp.c_str(), lp.c_str());
   }
 
   return instance;
@@ -211,8 +232,6 @@
               if ( lineStr.size() == 0 )
                 continue;
 
-              //std::cout << "line: '" << lineStr << "'" << std::endl; std::cout.flush();
-
               const std::string normalizedPath =
                   filesystem_path::normalize_path( lineStr, jarsDirPath.get_path());
 
@@ -226,8 +245,26 @@
 
   properties->setJVMClassPath(cp.str());
 
-  //std::cout << "JavaVMSingleton::computeClassPath: '" << cp << "'" << std::endl; std::cout.flush();
   return cp;
 }
 
+
+String JavaVMSingleton::computeLibPath(const zorba::StaticContext* aStaticContext)
+{
+  String lp;
+  std::vector<String> lCPV;
+  String pathSeparator(filesystem_path::get_path_separator());
+
+  aStaticContext->getFullLibPath(lCPV);
+  for (std::vector<String>::iterator lIter = lCPV.begin();
+       lIter != lCPV.end(); ++lIter)
+  {
+    String p = *lIter;
+    lp += pathSeparator + p;
+  }
+
+  return lp;
+}
+
+
 }} // namespace zorba, jvm

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to