Setting up project in Netbeans

Hello

This is the part 2 of the series about working with maven, spring, and hibernate together. In this post we will be using Linux Mint Nadia, a cousin of Ubuntu 12.10 and Netbeans.

Creating the project

  • Click: File > New Project
  • Categories: Maven > Project: Web Application
  • Click Next
  • creating new maven project
    Create new maven web project
  • Project Name: springDataMVCFamily
  • GroupId: net.djomeda.tutorials
  • Click: Next
  • After filling the 2 parts above the IDE will fill the rest of the fields

    project's name
    Writing project’s name
  • Make sure you have the setting like shown bellow
  • new_project_settings

    From my experiences it’s always good to have a web.xml file after creating a java web application

  • Click: File> New File
  • Categories: Web> File Types: Standard Deployment Descriptor (web.xml)
  • adding deployment description file using
    adding deployment description file using
  • Click: Next
  • Set the location to your WEB-INF folder which is assumed to be automatically generated by netbeans

    new_project_creating_web_xml_2

    We will note $TUTORIAL_HOME as where you created the project example: /media/Repo/netbeansworkspace/springDataMVCFamily for me.

  • Go to $TUTORIAL_HOME/src/main
  • create folder “resources” such as shown bellow
  • resources folder
    Creating the resources folder

    Once done Netbeans will automatically reload the folder structure and inside the IDE it will show like “Other Sources” in there, we will create our properties files to hold our parameters etc.

  • Do the same for $TUTORIAL_HOME/src/test/resources
  • It will be loaded in netbeans as “Other Test Sources”
    Let’s create the various java packages needed for this project

  • Right Click springDataMVCFamily > New > Java Package
    • net.djomeda.tutorials.springdatamvcfamily.controller
    • net.djomeda.tutorials.springdatamvcfamily.form
    • net.djomeda.tutorials.springdatamvcfamily.model
    • net.djomeda.tutorials.springdatamvcfamily.repository
    • net.djomeda.tutorials.springdatamvcfamily.service
  • Right Click: Other Sources > /src/main/resources > New > Other
  • Categories: Other > File Types: properties file
  • Create family.properties
  • Now let’s create prepare our project for all needed dependencies

  • Locate project files in the projects tab
  • Collapse the plus signe and click on pom.xml as shown bellow
  • edit maven pom
    Editing pom
  • Edit pom as shown bellow
  • [xml]
    <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>net.djomeda.tutorials</groupId>
    <artifactId>springDataMVCFamily</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>springDataMVCFamily</name>

    <properties>
    <hibernate.version>4.2.1.Final</hibernate.version>
    <mysql.connector.version>5.1.8</mysql.connector.version>
    <slf4j.version>1.6.6</slf4j.version>
    <logback.version>1.0.7</logback.version>
    <spring.version>3.2.2.RELEASE</spring.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.10</version>
    </dependency>
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.1</version>
    <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <!– Spring MVC –>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>${spring.version}</version>
    </dependency>

    <dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>2.2.2</version>
    </dependency>
    <dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <version>1.3.2.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.0-api</artifactId>
    <version>1.0.0.Final</version>
    </dependency>

    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>${hibernate.version}</version>
    </dependency>
    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>${hibernate.version}</version>
    </dependency>
    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-c3p0</artifactId>
    <version>${hibernate.version}</version>
    </dependency>

    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>4.0.2.GA</version>
    </dependency>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>${mysql.connector.version}</version>
    </dependency>
    <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j.version}</version>
    </dependency>
    <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>${slf4j.version}</version>
    </dependency>
    <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>${logback.version}</version>
    </dependency>
    <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>${logback.version}</version>
    </dependency>
    <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-access</artifactId>
    <version>${logback.version}</version>
    </dependency>

    </dependencies>

    <build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
    <source>1.6</source>
    <target>1.6</target>
    </configuration>
    </plugin>
    </plugins>
    </build>

    </project>

    [/xml]

    In order to build with maven, make sure the computer has access to internet

  • Let’s build our project: click on clean and build icon or press shift+ F11
  • clean and build
    clicking on clean and build icon

    If the build is successful and am sure it will , 😉 we can move to running the project

    successful build
    successful build

  • Let’s run our project: click on run icon or press F6
  • running hello world
    showing the infamous hello world

Voila, now that we are sure that our project is completely set and can run without an issue, let’s move on to the next part with is about creating models with JPA.

Leave a Reply

Your email address will not be published. Required fields are marked *

captcha * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top