How to put an external file on the classpath so code in karaf bundle can read it?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to put an external file on the classpath so code in karaf bundle can read it?

KARR, DAVID
I'm working on a project using Karaf 3.0.1 (can't upgrade).

A colleague has a situation where he's using an artifact that tries to load a properties file from the classpath using "getResource()", as opposed to "getResourceAsStream()".  We can't change this.

He's tried to place these properties file on disk and adding the path to that directory to the classpath when starting karaf.  When he steps through the code, it doesn't find those files.  I didn't watch his debugging steps, but he said that it appears to only use the bundle classloader, so augmenting the classpath on the karaf command line makes no difference.

I know about the ability to place ".cfg" files into karaf/etc and define persistent properties in a blueprint, but that doesn't help, because this artifact expects to find these properties files on the classpath.

What else can we do to make these files findable by "getResource()" from the code in the artifact?
Reply | Threaded
Open this post in threaded view
|

Re: How to put an external file on the classpath so code in karaf bundle can read it?

Guillaume Nodet-2
One way to achieve that is to put the config file in a fragment and attach it to your bundle. It will be able to access those without any problem then.

2017-10-17 22:34 GMT+02:00 KARR, DAVID <[hidden email]>:
I'm working on a project using Karaf 3.0.1 (can't upgrade).

A colleague has a situation where he's using an artifact that tries to load a properties file from the classpath using "getResource()", as opposed to "getResourceAsStream()".  We can't change this.

He's tried to place these properties file on disk and adding the path to that directory to the classpath when starting karaf.  When he steps through the code, it doesn't find those files.  I didn't watch his debugging steps, but he said that it appears to only use the bundle classloader, so augmenting the classpath on the karaf command line makes no difference.

I know about the ability to place ".cfg" files into karaf/etc and define persistent properties in a blueprint, but that doesn't help, because this artifact expects to find these properties files on the classpath.

What else can we do to make these files findable by "getResource()" from the code in the artifact?



--
------------------------
Guillaume Nodet

Reply | Threaded
Open this post in threaded view
|

RE: How to put an external file on the classpath so code in karaf bundle can read it?

KARR, DAVID

Won’t that still be deployed as a jar file?  Doesn’t that mean that “getResource()” (as opposed to “getResourceAsStream”) will fail?

 

From: Guillaume Nodet [mailto:[hidden email]]
Sent: Tuesday, October 17, 2017 1:52 PM
To: user <[hidden email]>
Subject: Re: How to put an external file on the classpath so code in karaf bundle can read it?

 

One way to achieve that is to put the config file in a fragment and attach it to your bundle. It will be able to access those without any problem then.

 

2017-10-17 22:34 GMT+02:00 KARR, DAVID <[hidden email]>:

I'm working on a project using Karaf 3.0.1 (can't upgrade).

A colleague has a situation where he's using an artifact that tries to load a properties file from the classpath using "getResource()", as opposed to "getResourceAsStream()".  We can't change this.

He's tried to place these properties file on disk and adding the path to that directory to the classpath when starting karaf.  When he steps through the code, it doesn't find those files.  I didn't watch his debugging steps, but he said that it appears to only use the bundle classloader, so augmenting the classpath on the karaf command line makes no difference.

I know about the ability to place ".cfg" files into karaf/etc and define persistent properties in a blueprint, but that doesn't help, because this artifact expects to find these properties files on the classpath.

What else can we do to make these files findable by "getResource()" from the code in the artifact?



 

--

------------------------
Guillaume Nodet

 

Reply | Threaded
Open this post in threaded view
|

Re: How to put an external file on the classpath so code in karaf bundle can read it?

Guillaume Nodet-2
THere's no difference between getResource() and getResourceAsStream() in the way the resource is obtained.
At the end, a call to getResourceAsStream(name) is the same as getResource(name).openStream().

What you need is a way to put your resource in the bundle classloader which can be done using a fragment.  

2017-10-17 23:18 GMT+02:00 KARR, DAVID <[hidden email]>:

Won’t that still be deployed as a jar file?  Doesn’t that mean that “getResource()” (as opposed to “getResourceAsStream”) will fail?

 

From: Guillaume Nodet [mailto:[hidden email]]
Sent: Tuesday, October 17, 2017 1:52 PM
To: user <[hidden email]>
Subject: Re: How to put an external file on the classpath so code in karaf bundle can read it?

 

One way to achieve that is to put the config file in a fragment and attach it to your bundle. It will be able to access those without any problem then.

 

2017-10-17 22:34 GMT+02:00 KARR, DAVID <[hidden email]>:

I'm working on a project using Karaf 3.0.1 (can't upgrade).

A colleague has a situation where he's using an artifact that tries to load a properties file from the classpath using "getResource()", as opposed to "getResourceAsStream()".  We can't change this.

He's tried to place these properties file on disk and adding the path to that directory to the classpath when starting karaf.  When he steps through the code, it doesn't find those files.  I didn't watch his debugging steps, but he said that it appears to only use the bundle classloader, so augmenting the classpath on the karaf command line makes no difference.

I know about the ability to place ".cfg" files into karaf/etc and define persistent properties in a blueprint, but that doesn't help, because this artifact expects to find these properties files on the classpath.

What else can we do to make these files findable by "getResource()" from the code in the artifact?



 

--

------------------------
Guillaume Nodet

 




--
------------------------
Guillaume Nodet