> -----original-----
> Sender: Shamik Bandopadhyay [mailto:[email protected]]
> Date: 2011/6/16 16:09
> Receiver: [email protected]
> Subject: Re: Spring resource classpath issue
> 
> Thanks for looking into this problem....
> 
> To answer your question, the file is a read/write object database. I
> tried externalizing the file instead of embedding it within the jar,

resource in bundle's class path cannot be write, you should put it in file 
system.

> unfortunately, using file://absolute_path throws the same exception.

Same exception may not be same reason. Make sure file url is correct; (etc: 
file:///d:/a, file:/d:/a, are both point to file d:\a. But file://d:/a is not a 
correct url);

> As per your observation, I'm not sure I understand the last point. You
> mentioned " OsgiBundleResource try locate File by your bundle's
> location on the file system; But it doesn't exist, so exception


resource.getURL() will return a resource url from bundle classpath; But you 
application called Resource.getFile(). 
So OsgiBundleResource will can only first try to locate it from bundle location 
(normally , bundle location  == url where you install bundle);

> raised."  I'm trying to understand the fact where does it differ
> compared to a non-osgi environment ? I've the same code running w/o an
> issue as long as the file is in the classpath.

Spring will choice the resource's implementation for you given url 
(classpath:/....db4o.). In osgi, OsgiBundleResource is choosed. But none osgi 
environment, ClassPathResource ,UrlResource,or something else(I am not sure) 
will be choosed;


> On Thu, Jun 16, 2011 at 12:38 AM, ext2 <[email protected]> wrote:
> >
> > The immediate cause is : db4o/ ObjectContainerFactoryBean is ask for a file
> on file system, so  OsgiBundleResource cannot return the resource on the
> classpath, the only thing OsgiBundleResource can do is try locate it from the
> bundle's location, but it doesn't exists;
> >
> > I am not familiar with db4o, so  I don't why it always ask for file , and
> cannot  ask for a input stream from class path resource;
> >
> > Is it a file only for read or a file for read/write?
> > 1) If it's a file only for read, maybe you can check the spring reference
> to see if other properties could configure it;
> > 2) if it's a file for read/write (etc a database file store data), maybe you
> should using store it on file system.
> >
> >
> >
> >
> >
> >
> > Spring dm 's OsgiBundleResource will try to locate the File from the 
> > location
> where you bundle installed.
> > This means :
> > 1) resource has been find in classpath
> > 2) other application is try  to use File relative to the bundle (here is
> the Db4o.openFile).
> > 3) OsgiBundleResource try locate File by your bundle's location on the file
> system; But it doesn't exist, so exception raised.
> >
> >> -----original -----
> >> Sender: Shamik Bandopadhyay [mailto:[email protected]]
> >> Date: 2011/6/16 15:04
> >> Receiver: [email protected]
> >> Subject: Re: Spring resource classpath issue
> >>
> >> I've checked that...here's the exception stack trace ...
> >>
> >> "caused by: java.io.FileNotFoundException: OSGi
> >> resource[classpath:taxonomy.db4o|
> >> nd.id=335|bnd.sym=taxonomydaoimplbundle] cannot be resolved to
> >> absolute file path
> >>        at
> >>
> org.springframework.osgi.io.OsgiBundleResource.getFile(OsgiBundleResorce.j
> >> ava:345)
> >>        at
> >>
> org.springmodules.db4o.ObjectContainerFactoryBean.afterPropertiesSet(bject
> >> ContainerFactoryBean.java:104)
> >>        at
> >>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanactor
> >> y.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
> >>        at
> >>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanactor
> >> y.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
> >>        ... 45 more
> >> aused by: java.io.FileNotFoundException: OSGi
> >>
> resource[classpath:taxonomy.db4o|nd.id=335|bnd.sym=taxonomydaoimplbundle]
> >> cannot be resolved to absolute file pah because it does not reside in
> >> the file system: bundle://335.0:1/taxonomy.db4o
> >>
> >>        at
> >> org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:242
> >>
> >>        at
> >> org.springframework.osgi.io.OsgiBundleResource.getFile(OsgiBundleReso
> >> rce.java:342)
> >>        ... 48 more"
> >>
> >> The exception is being thrown from spring OsgiBundleResource.getFile()
> method.
> >>
> >> It happens when spring module ObjectContainerFactoryBean is trying to
> >> execute the following code :
> >>
> >> if (databaseFile != null) {
> >>         container = Db4o.openFile(configuration,
> >> databaseFile.getFile().getAbsolutePath());
> >>        log.info("opened db4o local file-based objectContainer @" +
> >> ObjectUtils.getIdentityHexString(container));
> >> }
> >>
> >> databaseFile is a org.springframework.core.io.Resource object whose
> >> value is being injected by spring app context, i.e. the db4o path
> >> (classpath:META-INF/spring/repo/test.db4o) . The exception is
> >> happening at OsgiBundleResource.getFile() when
> >> ObjectContainerFactoryBean is trying to execute
> >> databaseFile.getFile().getAbsolutePath()).
> >>
> >> Here's the getFile() method in OsgiBundleResource.
> >>
> >> public File getFile() throws IOException {
> >>               // locate the file inside the bundle only known prefixes
> >>               if (searchType != OsgiResourceUtils.PREFIX_TYPE_UNKNOWN)
> {
> >>                       String bundleLocation = bundle.getLocation();
> >>                       int prefixIndex =
> >> bundleLocation.indexOf(ResourceUtils.FILE_URL_PREFIX);
> >>                       if (prefixIndex > -1) {
> >>                               bundleLocation =
> bundleLocation.substring(prefixIndex +
> >> ResourceUtils.FILE_URL_PREFIX.length());
> >>                       }
> >>                       File file = new File(bundleLocation, path);
> >>                       if (file.exists()) {
> >>                               return file;
> >>                       }
> >>                       // fall back to the URL discovery (just in case)
> >>               }
> >>
> >>               try {
> >>                       return ResourceUtils.getFile(getURI(),
> getDescription());
> >>               }
> >>               catch (IOException ioe) {
> >>                       throw (IOException) new
> >> FileNotFoundException(getDescription()
> >>                                       + " cannot be resolved to
> absolute file
> >> path").initCause(ioe);
> >>               }
> >>       }
> >>
> >> On Wed, Jun 15, 2011 at 11:07 PM, ext2 <[email protected]> wrote:
> >> > According to your resource, the Spring has find the the resource in
> classpath
> >> ( the url contains's the bundle id)
> >> >
> >> > But it seems the db4o is trying to use the classpath resource as a File.
> >> > Makesure if Db4o.openFile() can accept a classpath resource. if it 
> >> > cannot,
> >> Your exception will be reasonable;( I am not familiar with db4o, you can
> try
> >> it)
> >> >
> >> > I guess the exception is throw from Db4o, not from spring , is it?
> >> >
> >> >
> >> >> -----original-----
> >> >> Sender: Shamik Bandopadhyay [mailto:[email protected]]
> >> >> Date: 2011/6/15 9:25
> >> >> Receiver: [email protected]
> >> >> Subject: Re: Spring resource classpath issue
> >> >>
> >> >> Well, even with setting the context class loader through activator, it
> >> >> didn't work out. I'm still facing the issue, not sure what else I can
> >> >> do at this point. I saw the following article which confirms that
> >> >> spring dm takes care of the thread context loader issue.
> >> >>
> >> >>
> >>
> http://blog.springsource.com/2008/05/02/running-spring-applications-on-osg
> >> >> i-with-the-springsource-application-platform/
> >> >>
> >> >> On Tue, Jun 14, 2011 at 11:40 AM, Shamik Bandopadhyay 
> >> >> <[email protected]>
> >> >> wrote:
> >> >> > Thanks for the link John...my understanding was spring-extender is
> >> >> > supposed to take care of setting the right classloader instead of us
> >> >> > doing it explicitly in activator. It doesn't seem to be very
> >> >> > efficient. I'll give it a try by writing an activator and load the
> >> >> > Spring application context ....
> >> >> >
> >> >> > On Tue, Jun 14, 2011 at 7:25 AM,  <[email protected]> wrote:
> >> >> >> Take a look at this,
> >> >> >>
> >> >>
> >>
> http://www.dynamicjava.org/articles/osgi-matters/3rd-party-components-with
> >> >>
> >>
> -osgi/11-osgi-matters/43-3rd-party-components-incompatibility-problems?tmp
> >> >> l=component&print=1&page=
> >> >> >>
> >> >> >> Quoting Shamik Bandopadhyay <[email protected]>:
> >> >> >>
> >> >> >>> Well, that's the part which is puzzling. I don't see any reason why
> >> >> >>> Spring would use a seperate classloader.I've even tried including
> the
> >> >> >>> db4o file under
> >> >> >>>
> >> >> >>>
> >> >>
> >>
> <input-resource>META-INF/spring/repo/test.db4o=target/classes/META-INF/spr
> >> >> ing/repo/test.db4o</input-reource>
> >> >> >>> , but issue remains the same...
> >> >> >>>
> >> >> >>> On Mon, Jun 13, 2011 at 12:42 PM,  <[email protected]> wrote:
> >> >> >>>>
> >> >> >>>> I'm no expert but my best guess would be that spring is trying to
> load
> >> >> >>>> the
> >> >> >>>> file from the wrong classloader. If I'm reading the spring source
> >> >> >>>> correctly,
> >> >> >>>> it will attempt to load "classpath:META-INF/spring/repo/test.db4o"
> >> from
> >> >> >>>> Thread.currentThread().getContextClassLoader() and then from
> >> >> >>>> ClassUtils.class.getClassLoader() if that fails. That's my 2 cents
> >> >> >>>> anyway.
> >> >> >>>>
> >> >> >>>> Quoting Shamik Bandopadhyay <[email protected]>:
> >> >> >>>>
> >> >> >>>>> The file is in the same bundle and located inside
> >> >> >>>>> src/resources/META-INF/spring/repo/test.db4o. I've confirmed this
> in
> >> >> >>>>> the generated bundle as well.
> >> >> >>>>>
> >> >> >>>>> On Mon, Jun 13, 2011 at 8:40 AM, Tribon Cheng 
> >> >> >>>>> <[email protected]>
> >> >> >>>>> wrote:
> >> >> >>>>>>
> >> >> >>>>>> Resources are loaded in the same way as classes. Make sure the
> file
> >> is
> >> >> >>>>>> under
> >> >> >>>>>> the classpath, and is exported if it is used in different bundle.
> >> >> >>>>>> 在 2011-6-13 下午11:25,"Shamik Bandopadhyay"
> <[email protected]>
> >> 写
> >> >> 道:
> >> >> >>>>>>>
> >> >> >>>>>>> Hi,
> >> >> >>>>>>>
> >> >> >>>>>>> I'm trying to deploy a spring based bundle in osgi (fuse esb).In
> >> >> >>>>>>> spring context, I'm referring to a db4o file which is inside
> >> resources
> >> >> >>>>>>> folder. As per my understanding, a maven project will make sure
> that
> >> >> >>>>>>> any file available under resources folder will be available in
> >> project
> >> >> >>>>>>> classpath. I've kept the file under
> >> >> >>>>>>> resources/META-INF/spring/repo/test.db4o.
> >> >> >>>>>>>
> >> >> >>>>>>> Here's the entry in spring context.
> >> >> >>>>>>>
> >> >> >>>>>>> <bean id="objectContainer"
> >> >> >>>>>>> class="org.springmodules.db4o.ObjectContainerFactoryBean">
> >> >> >>>>>>>    <property name="databaseFile"
> >> >> >>>>>>> value="classpath:META-INF/spring/repo/test.db4o" />
> >> >> >>>>>>> </bean>
> >> >> >>>>>>>
> >> >> >>>>>>> Once I install and try to start the application, I'm getting the
> >> >> >>>>>>> following exception.
> >> >> >>>>>>>
> >> >> >>>>>>> "java.io.FileNotFoundException: OSGi
> >> >> >>>>>>> resource[classpath:META-INF/spring/repo/test.db4o|bnd.id
> >> >> >>>>>>
> >> >> >>>>>> =258|bnd.sym=taxonomydaoimplbundle]
> >> >> >>>>>>>
> >> >> >>>>>>> cannot be resolved to absolute file path because it does not 
> >> >> >>>>>>> reside
> >> >> in
> >> >> >>>>>>> the file system:
> bundle://258.0:1/META-INF/spring/repo/test.db4o"
> >> >> >>>>>>>
> >> >> >>>>>>> I've tried different combinations, but Felix doesn't seem to
> >> recognize
> >> >> >>>>>>> this file. Any pointer will be appreciated.
> >> >> >>>>>>>
> >> >> >>>>>>> - Thanks
> >> >> >>>>>>>
> >> >> >>>>>>>
> >> >> ---------------------------------------------------------------------
> >> >> >>>>>>> To unsubscribe, e-mail: [email protected]
> >> >> >>>>>>> For additional commands, e-mail: [email protected]
> >> >> >>>>>>>
> >> >> >>>>>>
> >> >> >>>>>
> >> >> >>>>>
> >> >> ---------------------------------------------------------------------
> >> >> >>>>> To unsubscribe, e-mail: [email protected]
> >> >> >>>>> For additional commands, e-mail: [email protected]
> >> >> >>>>>
> >> >> >>>>>
> >> >> >>>>
> >> >> >>>>
> >> >> >>>>
> >> >> >>>>
> >> >> >>>>
> >> ---------------------------------------------------------------------
> >> >> >>>> To unsubscribe, e-mail: [email protected]
> >> >> >>>> For additional commands, e-mail: [email protected]
> >> >> >>>>
> >> >> >>>>
> >> >> >>>
> >> >> >>>
> >> ---------------------------------------------------------------------
> >> >> >>> To unsubscribe, e-mail: [email protected]
> >> >> >>> For additional commands, e-mail: [email protected]
> >> >> >>>
> >> >> >>>
> >> >> >>
> >> >> >>
> >> >> >>
> >> >> >>
> >> >> >>
> ---------------------------------------------------------------------
> >> >> >> To unsubscribe, e-mail: [email protected]
> >> >> >> For additional commands, e-mail: [email protected]
> >> >> >>
> >> >> >>
> >> >> >
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: [email protected]
> >> >> For additional commands, e-mail: [email protected]
> >> >
> >> >
> >> >
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: [email protected]
> >> > For additional commands, e-mail: [email protected]
> >> >
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [email protected]
> >> For additional commands, e-mail: [email protected]
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to