Uploaded image for project: 'Karaf'
  1. Karaf
  2. KARAF-1545

Jar files in lib directory require "karaf-" prefix in order to be loaded

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.2
    • Fix Version/s: 2.4.0, 3.0.2, 2.3.6, 4.0.0.M3
    • Labels:
      None
    • Environment:

      Java version: 1.6.0_32, vendor: Sun Microsystems Inc.
      Java home: /home/jcarman/Programs/jdk1.6.0_32/jre
      Default locale: en_US, platform encoding: UTF-8
      OS name: "linux", version: "3.2.0-24-generic", arch: "amd64", family: "unix"

      Description

      I was trying to configure JDBC fail-over, so I put my mysql driver jar in the KARAF_HOME/lib directory. I kept getting ClassNotFoundExceptions. On the advice of someone on IRC, I changed the name to "karaf-mysql-connector-java.jar" and it started working. Why the karaf- prefix requirement? If that's the intended behavior, then please update the README file in the lib directory. It says:

      "Any jar in this folder will be part of the main classloader used to load Karaf."

        Issue Links

          Activity

          Show
          jbonofre Jean-Baptiste Onofré added a comment - Fixed on karaf-2.3.x: https://git-wip-us.apache.org/repos/asf?p=karaf.git;a=commitdiff;h=0d59d06154bd2a693d8b67ec066b76c013fd464f
          Show
          jbonofre Jean-Baptiste Onofré added a comment - Fixed on karaf-2.x: https://git-wip-us.apache.org/repos/asf?p=karaf.git;a=commitdiff;h=892528f4848a817419335aa65e75bce230873ac5
          Show
          jbonofre Jean-Baptiste Onofré added a comment - Fixed on karaf-3.0.x: https://git-wip-us.apache.org/repos/asf?p=karaf.git;a=commitdiff;h=08dca7aa79ab417c6b9c6cda92a599f9ca798dc1
          Show
          jbonofre Jean-Baptiste Onofré added a comment - Fixed on master: https://git-wip-us.apache.org/repos/asf?p=karaf.git;a=commitdiff;h=2cc74ed9094f9492245d5d2326febe4a45fefdc3
          Hide
          jbonofre Jean-Baptiste Onofré added a comment -

          Thanks Guillaume, I'm updating the doc.

          Show
          jbonofre Jean-Baptiste Onofré added a comment - Thanks Guillaume, I'm updating the doc.
          Hide
          gnt Guillaume Nodet added a comment -

          The libraries in lib/ext/ don't need to be prefixed by karaf-, only those in lib/.

          Show
          gnt Guillaume Nodet added a comment - The libraries in lib/ext/ don't need to be prefixed by karaf- , only those in lib/ .
          Hide
          jbonofre Jean-Baptiste Onofré added a comment -

          Documentation up to date on master.

          Show
          jbonofre Jean-Baptiste Onofré added a comment - Documentation up to date on master.
          Hide
          jbonofre Jean-Baptiste Onofré added a comment -

          Good idea. Let me do that.

          Show
          jbonofre Jean-Baptiste Onofré added a comment - Good idea. Let me do that.
          Hide
          jwcarman James Carman added a comment -

          How about just fix the documentation? The intended behavior was that only karaf-prefixed jars would be loaded, so the docs are obviously wrong.

          Show
          jwcarman James Carman added a comment - How about just fix the documentation? The intended behavior was that only karaf-prefixed jars would be loaded, so the docs are obviously wrong.
          Hide
          jbonofre Jean-Baptiste Onofré added a comment -

          ping ?

          Show
          jbonofre Jean-Baptiste Onofré added a comment - ping ?
          Hide
          jbonofre Jean-Baptiste Onofré added a comment -

          Guys, what do we do with this Jira ?

          Show
          jbonofre Jean-Baptiste Onofré added a comment - Guys, what do we do with this Jira ?
          Hide
          charly Heath Kesler added a comment -

          Ok, this was reverted on 2.2.12, 2.3.2, 2.4, 3.0

          I will look into adding a sub-directory for lib/app for putting the jdbc drivers in without having the add the karaf prefix.

          Show
          charly Heath Kesler added a comment - Ok, this was reverted on 2.2.12, 2.3.2, 2.4, 3.0 I will look into adding a sub-directory for lib/app for putting the jdbc drivers in without having the add the karaf prefix.
          Hide
          jwcarman James Carman added a comment -

          The failover is a Karaf feature, not an "app" feature.

          Show
          jwcarman James Carman added a comment - The failover is a Karaf feature, not an "app" feature.
          Hide
          charly Heath Kesler added a comment -

          +1 on that, I will revert the lib changes to use karaf* then look at adding the subfolder.

          Show
          charly Heath Kesler added a comment - +1 on that, I will revert the lib changes to use karaf* then look at adding the subfolder.
          Hide
          ffang Freeman Fang added a comment -

          Hi,

          If the jdbc driver is used for failover, as Guillaume suggested, we can add a lib/app/ folder and put the jdbc drivers in, this keep current behavior as is and also can accommodate your scenario, take a look at the discussion here[1] to get more details

          [1]http://karaf.922171.n3.nabble.com/discussion-thoughts-on-https-issues-apache-org-jira-browse-KARAF-1545-td4028653.html

          Freeman

          Show
          ffang Freeman Fang added a comment - Hi, If the jdbc driver is used for failover, as Guillaume suggested, we can add a lib/app/ folder and put the jdbc drivers in, this keep current behavior as is and also can accommodate your scenario, take a look at the discussion here [1] to get more details [1] http://karaf.922171.n3.nabble.com/discussion-thoughts-on-https-issues-apache-org-jira-browse-KARAF-1545-td4028653.html Freeman
          Hide
          charly Heath Kesler added a comment -

          Hi,

          Doesn't the jdbc jars have to be loaded for locking before bundles get started? I didn't think that installing them as bundles would fix the issue described in the ticket, if I remember correctly.

          Heath

          Show
          charly Heath Kesler added a comment - Hi, Doesn't the jdbc jars have to be loaded for locking before bundles get started? I didn't think that installing them as bundles would fix the issue described in the ticket, if I remember correctly. Heath
          Hide
          ffang Freeman Fang added a comment -

          Hi,

          I'm also a little bit concerned about this change.

          IMO the jars in KARAF_HOME/lib which could get loaded by default should be only those that do very fundamental karaf bootstrap work, any other libs should be installed and managed as OSGi bundle(including the JDBC driver)

          Or for example in KARAF_HOME/lib folder we also have org.apache.servicemix.specs.activator.jar since Karaf 2.3.x(used for endorsed specs), this isn't added in the current Karaf launch script CLASSPATH, we build a URLClassLoader to load it in org.apache.karaf.main.Main.

          Freeman

          Show
          ffang Freeman Fang added a comment - Hi, I'm also a little bit concerned about this change. IMO the jars in KARAF_HOME/lib which could get loaded by default should be only those that do very fundamental karaf bootstrap work, any other libs should be installed and managed as OSGi bundle(including the JDBC driver) Or for example in KARAF_HOME/lib folder we also have org.apache.servicemix.specs.activator.jar since Karaf 2.3.x(used for endorsed specs), this isn't added in the current Karaf launch script CLASSPATH, we build a URLClassLoader to load it in org.apache.karaf.main.Main. Freeman
          Hide
          danttran Dan Tran added a comment -

          Yes, i also meant karaf_home/lib directory. I dont think this directory is for karaf only. and also blind-fully load all jars under a popular directory sound dangerous.

          May be we should make lib/karaf reserve for karaf?

          Show
          danttran Dan Tran added a comment - Yes, i also meant karaf_home/lib directory. I dont think this directory is for karaf only. and also blind-fully load all jars under a popular directory sound dangerous. May be we should make lib/karaf reserve for karaf?
          Hide
          jwcarman James Carman added a comment -

          The "lib" directory we're talking about here is the one in KARAF_HOME. Not some application-specific lib directory.

          Show
          jwcarman James Carman added a comment - The "lib" directory we're talking about here is the one in KARAF_HOME. Not some application-specific lib directory.
          Hide
          jwcarman James Carman added a comment -

          It will only surprise folks who put jars in the lib directory and counted on them not being picked up because they didn't have the "karaf-" prefix. The documentation says that any jar in that directory should be picked up, so they would have to be taking advantage of this bug in order to be "surprised."

          Show
          jwcarman James Carman added a comment - It will only surprise folks who put jars in the lib directory and counted on them not being picked up because they didn't have the "karaf-" prefix. The documentation says that any jar in that directory should be picked up, so they would have to be taking advantage of this bug in order to be "surprised."
          Hide
          danttran Dan Tran added a comment - - edited

          this enhancement will create surprise to existing user base.

          Also, lib is universal 'lib' directory used by lots of appl and genenated script ( ie produce by appassembler-maven-plugin), each script can place jar file under lib and hand pick the exacts jars to be loaded into the script's main class ( same for karaf ). This is a good contract which to be broken when next release of karaf that has this enhancement

          Show
          danttran Dan Tran added a comment - - edited this enhancement will create surprise to existing user base. Also, lib is universal 'lib' directory used by lots of appl and genenated script ( ie produce by appassembler-maven-plugin), each script can place jar file under lib and hand pick the exacts jars to be loaded into the script's main class ( same for karaf ). This is a good contract which to be broken when next release of karaf that has this enhancement
          Hide
          charly Heath Kesler added a comment -

          @Dan - So are you putting jar files in the lib directory that you do not expect/want to be available to Karaf? If so then you will have to move them outside of the lib directory.

          Show
          charly Heath Kesler added a comment - @Dan - So are you putting jar files in the lib directory that you do not expect/want to be available to Karaf? If so then you will have to move them outside of the lib directory.
          Hide
          danttran Dan Tran added a comment -

          My existing 2.2.x and 2.3.x karaf has a bunch of other jar we put in for other command line purpose. What is the impact on this enhancement? would this get karaf to confuse due to unknown jars?

          Show
          danttran Dan Tran added a comment - My existing 2.2.x and 2.3.x karaf has a bunch of other jar we put in for other command line purpose. What is the impact on this enhancement? would this get karaf to confuse due to unknown jars?
          Hide
          jwcarman James Carman added a comment -

          Nice work, Heath! Thanks, man.

          Show
          jwcarman James Carman added a comment - Nice work, Heath! Thanks, man.
          Hide
          charly Heath Kesler added a comment -

          back ported the changes to 2.2.12, 2.3.2, 2.4.0. Tested using the postgresql with the lock configuration on a mac and windows.

          Show
          charly Heath Kesler added a comment - back ported the changes to 2.2.12, 2.3.2, 2.4.0. Tested using the postgresql with the lock configuration on a mac and windows.
          Hide
          jwcarman James Carman added a comment -

          It was reported against 2.2, so I would hope it would get all the way back to there, unless that's not supported any more. Thanks, Heath!

          Show
          jwcarman James Carman added a comment - It was reported against 2.2, so I would hope it would get all the way back to there, unless that's not supported any more. Thanks, Heath!
          Hide
          charly Heath Kesler added a comment -

          Should this be back ported to 2.3?

          Show
          charly Heath Kesler added a comment - Should this be back ported to 2.3?
          Hide
          charly Heath Kesler added a comment -

          I made the change to both the unix shell and the bat file for windows and tested on both using the postgres driver jar.

          Show
          charly Heath Kesler added a comment - I made the change to both the unix shell and the bat file for windows and tested on both using the postgres driver jar.
          Hide
          charly Heath Kesler added a comment -

          I am attaching the change that allows any jar in the lib directory to be loaded, NOT just the ones that prefix with 'karaf'.

          Show
          charly Heath Kesler added a comment - I am attaching the change that allows any jar in the lib directory to be loaded, NOT just the ones that prefix with 'karaf'.
          Hide
          pieber Andreas Pieber added a comment -

          btw, it might be worth bringing this topic to the dev list; wdyt?

          Show
          pieber Andreas Pieber added a comment - btw, it might be worth bringing this topic to the dev list; wdyt?
          Hide
          pieber Andreas Pieber added a comment -

          tbh I was always curious about the behavior that we only load karaf-*.jar files from the lib directory. Would make more sense (imho) to load all jar files from this dir.

          From the difficulty it would be

          a) change the readme
          b) load .jar instead of karaf-.jar
          c) add a new folder for *.jar

          I would rather tend to option (b) but I've no problem with getting over voted

          Show
          pieber Andreas Pieber added a comment - tbh I was always curious about the behavior that we only load karaf-*.jar files from the lib directory. Would make more sense (imho) to load all jar files from this dir. From the difficulty it would be a) change the readme b) load .jar instead of karaf- .jar c) add a new folder for *.jar I would rather tend to option (b) but I've no problem with getting over voted
          Hide
          jwcarman James Carman added a comment -

          I don't like the idea of having to muck with the CLASSPATH environment variable. Nobody really does that anymore, do they? Perhaps adding a new folder "third-party" in the lib directory and put that README in there? That wouldn't change the functionality, really. It would only break anyone who put a third-party folder in their lib directory manually.

          Show
          jwcarman James Carman added a comment - I don't like the idea of having to muck with the CLASSPATH environment variable. Nobody really does that anymore, do they? Perhaps adding a new folder "third-party" in the lib directory and put that README in there? That wouldn't change the functionality, really. It would only break anyone who put a third-party folder in their lib directory manually.
          Hide
          jgoodyear Jamie goodyear added a comment -

          A simple update would be to update the README and online documents to state that the user should add the jar directly to the CLASSPATH environment variable. I'm not sure that changing the current behaviour at this point in the 2.2.x line would be entirely safe.

          Show
          jgoodyear Jamie goodyear added a comment - A simple update would be to update the README and online documents to state that the user should add the jar directly to the CLASSPATH environment variable. I'm not sure that changing the current behaviour at this point in the 2.2.x line would be entirely safe.
          Hide
          jgoodyear Jamie goodyear added a comment -

          The lib folder currently only auto adds "karaf*.jar" to the classpath. The work around to this behaviour is to add the jar directly to CLASSPATH in your environment.

          Show
          jgoodyear Jamie goodyear added a comment - The lib folder currently only auto adds "karaf*.jar" to the classpath. The work around to this behaviour is to add the jar directly to CLASSPATH in your environment.

            People

            • Assignee:
              jbonofre Jean-Baptiste Onofré
              Reporter:
              jwcarman James Carman
            • Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development