Hibernate Development Environment with Eclipse and Maven
This tutorial is part of the Hibernate introduction series. This is to help setup and getting started with Hibernate. Needless to say, we need JDK. Our choice of IDE is Eclipse, build tool is Maven. You can do with Netbeans or any other editor. ANT or any other build tool is also fine.
Tools used to setup the environment:
- Java JDK
- Eclipse IDE
- Maven Build Tool
- Hibernate 4.x
Ensure that you have some version of JDK configured as below in Eclipse preferences.
If you have setup Maven correctly, you should have preferences similar to the following
Create Maven Project
Maven is a build tool by Apache, it will help to manage the dependencies better. Now, I will create Standard Java Project, add required JARs, compile and package using Maven. All of these listed tasks are executed by Maven behind you.
Following below steps are the needed steps for creating full-fledged Java Project with all required Hibernate libraries.
- Open Eclipse ide, from Project Explorer, right-click and choose New and Other.
- Expand Maven node and choose Maven Project.
- Click next and next.
- From Maven Project, select maven-archetype-quickstart.
- Determine your groupId, artifactId, version and your default packages. These information is required by Maven for dependencies identification purposes. If you do not have any clue about this, refer below and do similar to that.
- Click Finish.
- Your project should look like
Add Required Dependencies for Hibernate
For now, your Hibernate project is created but still you need to add required dependencies/libraries that Hibernate requires to work.
For getting started with Hibernate, the required libraries are:
The projects Maven pom.xml is as below,
Maven pom.xml for Hibernate and MySql dependencies
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.javapapers</groupId> <artifactId>Hibernate-Sample</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>Hibernate-Sample</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>4.3.6.Final</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.31</version> </dependency> </dependencies> </project>
With this a basic shell project is ready for Hibernate based development. In the next tutorial we will see how to configure the Hibernate properties, session and connect the database.
This Hibernate tutorial was added on 08/10/2014.