hibernate resource not found when run inside eclipse

I use Hibernate 3 in Eclipse with Hibernate Synchronizer. When I run code that uses hibernate from the command line (executed using ant) it also works fine. However, if I run that same app in eclipse it fails with the error message at the end of this question.

The problem is that when run from inside eclipse "Thread.currentThread().getContextClassLoader().getResourceAsStream( path )" returns null whereas it succeeds when run outside of eclipse.

What should I do to get this to run inside eclipse?

ERROR[2006-04-04 22:15:27,545] com.knowlist.search.IndexUpdaterQueueManager.main(IndexUpdaterQueueManager.java:39)(IndexUpdaterQueueManager.java39):
java.lang.RuntimeException: org.hibernate.MappingException: Resource: /com/knowlist/list/hh/CustomObjAffinity.hbm not found
      at com.knowlist.list.hh.HibernateInit.doInit(HibernateInit.java:66)
      at com.knowlist.list.hh.HibernateInit.doInit(HibernateInit.java:25)
      at com.knowlist.search.IndexUpdaterQueueManager.main(IndexUpdaterQueueManager.java:29)
Caused by: org.hibernate.MappingException: Resource: /com/knowlist/list/hh/CustomObjAffinity.hbm not found
      at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
      at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1313)
      at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1285)
      at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1267)
      at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1234)
      at org.hibernate.cfg.Configuration.configure(Configuration.java:1162)
      at com.knowlist.list.hh.base._BaseRootDAO.initialize(_BaseRootDAO.java:57)
      at com.knowlist.list.hh.base._BaseRootDAO.initialize(_BaseRootDAO.java:41)
      at com.knowlist.list.hh.HibernateInit.doInit(HibernateInit.java:35)
      ... 2 more
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

make sure th resource your are looking for is in the build path
if its in a jar, add that jar
if its in a directory then make sure it is a source directory

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HappyEngineerAuthor Commented:
I found that if I run it using ant from either the command line or from inside eclipse then it executes fine. However, if I execute it directly in eclipse then it fails in the way described above.

I opened up the run configuration in eclipse for this app and set the classpath up to be just like that in the build file and it didn't make any difference.
Whare is CustomObjAffinity.hbm
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

HappyEngineerAuthor Commented:
It's at:

The ant target (which works):
      <target name="indexUpdater">
            <java classname="com.knowlist.search.IndexUpdaterQueueManager">
                        <pathelement location="WebRoot/WEB-INF/classes"/>
                        <fileset dir="WebRoot/WEB-INF/lib">
                              <include name="*.jar"/>

according to that error it should be in:

When executing directly through Eclipse, set the classpath variables the same as in the ANT script. You will need to specifically add J:\prog\workspace\KnowList\WebRoot\WEB-INF\classes to the classpath to the Eclipse run time environment.
Mayank SAssociate Director - Product EngineeringCommented:
You can add it to the Run configuration in Eclipse.
HappyEngineerAuthor Commented:
I found that the problem went away when I removed the preceding slash from the beginning of the hbm. So, instead of "/com/knowlist/list/hh/CustomObjAffinity.hbm" I use "com/knowlist/list/hh/CustomObjAffinity.hbm".
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.