Skip to Content
author's profile photo Former Member
Former Member

Loading files from within the ejb-jar using the classloader


i'm trying the following setup;

1/ A J2EE Server Library for hibernate

2/ A Stateless SessionBean using hibernate to create an object in the DB

3/ A Webservice invoking the session bean.

The EAR is already deployed ok and i can call the WebService.

When the SessionBean tries to instantiate the Factory from hibernate, hibernate in term loads a configuration file by the name "/hibernate.cfg.xml" which is contained in the ejb-jar. (I've checked this with jar tvf).

Nevertheless the Factory is unable to find the file.

Is there anything special wrt loading files from inside the ejb-jar in webas ?

regards, Udo

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jun 23, 2004 at 10:12 AM

    I did some further analyis on that and come to the following conclusion:

    1/ The hibernate.jar gets loaded with a classloader attached to the Lib-Project

    2/ The EJBs get loaded using the ApplicationClassloader

    Since the files which are not loadable by hibernate reside in the ejb-jar they are not loadable since the classloader from the lib-project does not see the ejb-jar.

    Could somebody shed some light on that please ?

    regards, udo

    Add a comment
    10|10000 characters needed characters exceeded

    • Hello Udo,

      Hibernate use the context ClassLoader to resolve resources that are application dependent (fixed in version 1.1). However the and hibernate.cfg.xml are loaded explicitly with the classloader of the Hibernate library. That makes me think that, this XML document should reside in the library.

      If this is unacceptable for you I would suggest that you change the net.sf.hibernate.cfg.Congiuration class of Hibernate to use Thread.currentThread().getContextClassLoader() classloader to load the XML document.

      Best Regards,


Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.