Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6850145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:05:17+00:00 2026-05-27T01:05:17+00:00

I have web project based on Hibernate and Spring (programmatic configuration). The Hibernate mappings

  • 0

I have web project based on Hibernate and Spring (programmatic configuration). The Hibernate mappings are provided in a package which is archived in a JAR.

When it comes to initialize the session factory I used to call:

sessionFactory.
    setMappingDirectoryLocations(new Resource[]{
        new ClassPathResource("org/all/theway/to/hibernatemappings")});

in order to tell Hibernate where to look for mapping files. “org/all/theway/to/hibernatemappings” is the package which contains the hbm.xml files. This worked fine within Eclipse (GWT dev mode), as the mapping-containing project is also checked out and linked to my web project. However, once I create a war and deploy it to Tomcat, it fails to get the class path resource.

Spring’s ClasspathResource javadoc implies this: “Supports resolution as java.io.File if the class path resource resides in the file system, but not for resources in a JAR. Always supports resolution as URL. “

But what to do instead? I could also use setMappingJarLocation instead, but I do not like to hardcode a jar file name in my Spring context. Further, when I tried it, it also only worked within IDE, but inside Tomcat the same file path (WEB-INF/lib/file.jar) did not work. This also makes me believe that this would be an ugly solution.

Is there a workaround which works without using the jar file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:05:18+00:00Added an answer on May 27, 2026 at 1:05 am

    Not really a solution of the original problem but a workarounnd which avoids dealing with filesystem file names of jar files within the configuration code:

    I simply told ant to unpack the JAR in question into the WEB-INF/classes folder

    <target name="unpack.hibernatemappings">
        <unzip dest="${war.dir}/WEB-INF/classes">
            <fileset dir="${lib.dir}">
                <include name="archive-containing-the-hbm-files.jar"/>
            </fileset>
        </unzip>
    </target>
    

    Now, the Hibernate mappings reside in the file system and can be accessed as ClassPathResource (like in the questions’s example).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a web project that is Spring+Hibernate+MySQL based. I am stuck
I have a Spring MVC based Web Application with Hibernate. Following is the directory
I have inherited a web project that is perl based and I'm attempting to
I have this web based project written in Perl and I have to migrate
I am working on a web based project in my free time. I have
I have gwt web project, which must use application.properties (on client side) loaded as
We have just started our new assignment - web-based project. Before I get directly
I have an existing, fully functional Spring web application based on Spring 2.5.6 -
I'm working on a large web project based on LAMP stack. I have to
I have a large non-Java EE, JSF-based web app project. Our system is layered

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.