You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by si...@apache.org on 2018/07/17 07:32:36 UTC

[bookkeeper] branch master updated: ISSUE #1542: Unable to run 'bookkeeper' shell script from /bookkeeper/bin folder

This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new b1d23b4  ISSUE #1542: Unable to run 'bookkeeper' shell script from /bookkeeper/bin folder
b1d23b4 is described below

commit b1d23b483a06f987efab8b794a9e754dc4552542
Author: Sijie Guo <si...@apache.org>
AuthorDate: Tue Jul 17 00:32:27 2018 -0700

    ISSUE #1542: Unable to run 'bookkeeper' shell script from /bookkeeper/bin folder
    
    Descriptions of the changes in this PR:
    
    *Bug*
    
    ```
    Getting NoClassDefFoundError while trying to run 'bookkeeper' shell script from 'bin' folder. Issue seems to be related with classpath (cached classpath file - cached_classpath.txt)
    
    ~/Workspace/Community/bookkeeper/bin$ ./bookkeeper shell
    JAVA_HOME not set, using java from PATH. (/usr/bin/java)
    cat: bookkeeper-server/target/cached_classpath.txt: No such file or directory
    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/configuration/Configuration
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.configuration.Configuration
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more
    ```
    
    *Motivation*
    
    Fixes #1542
    
    *Problem*
    
    `bin/common.sh` uses a relative path for caching classpath and locating the pom file.
    
    *Changes*
    
    - change to use full path for cached classpath file and the module pom file
    - add a test case to cover this problem
    
    Master Issue: #1542
    
    Author: Sijie Guo <si...@apache.org>
    
    Reviewers: Charan Reddy Guttapalem <re...@gmail.com>
    
    This closes #1548 from sijie/fix_issue_1542, closes #1542
---
 bin/common.sh                                     |  6 +++---
 tests/scripts/src/test/bash/bk_test_bin_common.sh | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/bin/common.sh b/bin/common.sh
index 0a0146f..d54b1d5 100755
--- a/bin/common.sh
+++ b/bin/common.sh
@@ -181,9 +181,9 @@ add_maven_deps_to_classpath() {
   # Need to generate classpath from maven pom. This is costly so generate it
   # and cache it. Save the file into our target dir so a mvn clean will get
   # clean it up and force us create a new one.
-  f="${MODULE_PATH}/target/cached_classpath.txt"
+  f="${BK_HOME}/${MODULE_PATH}/target/cached_classpath.txt"
   if [ ! -f ${f} ]; then
-    ${MVN} -f "${MODULE_PATH}/pom.xml" -Dstream dependency:build-classpath -Dmdep.outputFile="target/cached_classpath.txt" &> /dev/null
+    ${MVN} -f "${BK_HOME}/${MODULE_PATH}/pom.xml" -Dstream dependency:build-classpath -Dmdep.outputFile="target/cached_classpath.txt" &> /dev/null
   fi
 }
 
@@ -197,7 +197,7 @@ set_module_classpath() {
     echo ${BK_CLASSPATH}
   else
     add_maven_deps_to_classpath ${MODULE_PATH} >&2
-    cat ${MODULE_PATH}/target/cached_classpath.txt
+    cat ${BK_HOME}/${MODULE_PATH}/target/cached_classpath.txt
   fi
   return
 }
diff --git a/tests/scripts/src/test/bash/bk_test_bin_common.sh b/tests/scripts/src/test/bash/bk_test_bin_common.sh
index 0c726ea..8e81f92 100644
--- a/tests/scripts/src/test/bash/bk_test_bin_common.sh
+++ b/tests/scripts/src/test/bash/bk_test_bin_common.sh
@@ -172,6 +172,28 @@ testLoadEnvfiles() {
   unset BK_HOME
 }
 
+testSetModuleClasspath() {
+  TEST_DIR=${BK_TMPDIR}/test_set_module_classpath
+  mkdir -p ${TEST_DIR}
+  BK_HOME=${TEST_DIR}
+
+  # prepare the env files
+  mkdir -p ${BK_HOME}/conf
+  echo "" > ${BK_HOME}/conf/nettyenv.sh
+  echo "" > ${BK_HOME}/conf/bkenv.sh
+  echo "" > ${BK_HOME}/conf/bk_cli_env.sh
+
+  source ${BK_BINDIR}/common.sh
+
+  MODULE_PATH="testmodule"
+
+  mkdir -p ${BK_HOME}/${MODULE_PATH}/target
+  echo "test-classpath" > ${BK_HOME}/${MODULE_PATH}/target/cached_classpath.txt
+
+  local result=$(set_module_classpath ${MODULE_PATH})
+  assertEquals "test-classpath" ${result}
+}
+
 testBuildBookieJVMOpts() {
   source ${BK_BINDIR}/common.sh