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 494293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:29:01+00:00 2026-05-13T05:29:01+00:00

I´m busy converting an existing project from an Ant build to one using Maven.

  • 0

I´m busy converting an existing project from an Ant build to one using Maven. Part of this build includes using the hibernate hbm2java tool to convert a collection of .hbm.xml files into Java. Here’s a snippet of the Ant script used to do this:

<target name="dbcodegen" depends="cleangen" 
        description="Generate Java source from Hibernate XML">
  <hibernatetool destdir="${src.generated}">
    <configuration>   
      <fileset dir="${src.config}">
        <include name="**/*.hbm.xml"/>
      </fileset>
    </configuration>   
    <hbm2java jdk5="true"/>
  </hibernatetool>   
</target>

I’ve had a look around on the internet and some people seem to do this (I think) using Ant within Maven and others with the Maven plugin. I’d prefer to avoid mixing Ant and Maven. Can anyone suggest a way to do this so that all of the .hbm.xml files are picked up and the code generation takes place as part of the Maven code generation build phase?

Thanks!

Adam.

  • 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-13T05:29:01+00:00Added an answer on May 13, 2026 at 5:29 am

    Well, there is the Maven Hibernate3 Plugin if you don’t want to mix Ant and Maven (which is a good idea here IMO). It has a hbm2java goal which is bound by default to the generate-sources phase. Refer to the website of the Mojo for more details but the setup of the plugin might looks like something like this:

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>hibernate3-maven-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <goals>
              <goal>hbm2java</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <components>
            <component>
              <name>hbm2java</name>
              <implementation>configuration</implementation>
              <outputDirectory>target/generated-sources/hibernate3</outputDirectory>
            </component>
          </components>
          <componentProperties>
            <drop>true</drop>
            <jdk5>true</jdk5>
            <configurationfile>/src/main/resources/hibernate.cfg.xml</configurationfile>
          </componentProperties>
        </configuration>
      </plugin> 
    

    EDIT: The plugin actually looks for .hbm.xml in target/classes to generate the java source files. So, if you put your mapping files in src/main/resources, they will get copied into target/classes during the process-resources phase which is invoked by the plugin and things will just work. I’ve just tested this with the following sample project:

    maven-hibernate3-testcase
    |-- pom.xml
    `-- src
        |-- main
        |   |-- java
        |   `-- resources
        |       |-- Person.hbm.xml
        |       `-- hibernate.cfg.xml
        `-- test
            `-- java
    

    The pom.xml is almost empty, it just contains the plugin configuration seen above and a junit dependency. The hibernate.cfg.xml contains:

    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
      <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
        <property name="connection.url">jdbc:derby://localhost:1527/mydatabase</property>
        <property name="connection.username">app</property>
        <property name="connection.password">app</property>
    
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>
    
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.DerbyDialect</property>
    
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">false</property>
    
        <!-- Mapping files -->
        <mapping resource="Person.hbm.xml" />
      </session-factory>
    </hibernate-configuration>
    

    And Person.hbm.xml looks as follow:

    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-mapping
       PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
       "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    
    <hibernate-mapping>
    
      <class name="Person" table="person">
        <id name="id" type="int">
          <generator class="increment" />
        </id>
    
        <property name="name" column="cname" type="string" />
      </class>
    
    </hibernate-mapping>
    

    With this configuration, running mvn install generates Person.java as shown below:

    $ cat target/generated-sources/hibernate3/Person.java 
    // default package
    // Generated Dec 14, 2009 2:19:22 PM by Hibernate Tools 3.2.2.GA
    
    
    
    /**
     * Person generated by hbm2java
     */
    public class Person  implements java.io.Serializable {
    
    
         private int id;
         private String name;
    
        public Person() {
        }
    
        public Person(String name) {
           this.name = name;
        }
    
        public int getId() {
            return this.id;
        }
    
        public void setId(int id) {
            this.id = id;
        }
        public String getName() {
            return this.name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
    
    
    
    }
    

    Everything works as described.

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

Sidebar

Related Questions

I'll be embarking on converting one of our old, legacy apps from VB6 to
I'm busy using Google Charts in one of my projects to display data in
I am busy writing my thesis (so, I guess this could count as a
Help I am busy making changes to a type library in a Datasnap project.
I'm busy implementing the wurfl api using PHP, but somehow just can't seem to
i am using following webservices for retrieving data from server server side:.net client side:ksoap2
I am busy on a project that involves calling the API's of nine other
I am busy writing a login page in Silverlight. I am using an Authentication
I am busy developing a chrome extension. What it will do: Get data from
I am busy working on this and thought I would put it our there.

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.