ObjectDB ObjectDB

Step 1: Create a Maven Web Project

We start by creating a new Maven-WTP dynamic web project in Eclipse:

  • Open the [New Project] dialog box, e.g. by using File > New > Project...
  • Select Maven > Maven Project and click Next.
  • Verify that the Create a simple project checkbox is disabled and click Next.
  • Enter maven-archetype-webapp as a filter, select maven-archetype-webapp in the artifact list and click Next.

  • Enter Group Id (e.g. Guestbook), Artifact Id (e.g. Guestbook), Version (e.g. 1.0) and Package (guest), and click Finish to create the project.

The configuration of the new created project is contained in a pom.xml file that was created in the project main folder:

Note: You should verify now that Maven Integration for WTP is installed, by right clicking the project node and checking that the Run As > Run on Server command is available. If it is not available - you have to install Maven Integration for WTP and create a new project.

To add dependency on the Spring MVC Framework and ObjectDB and to automatically download all the required JAR files from Maven repositories - open the pom.xml file and in the pom.xml tab use copy and paste to replace its content with the following settings:

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.objectdb.tutorial.spring</groupId>
<artifactId>Guestbook</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>Guestbook</name>
<url>http://maven.apache.org</url>
<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
  <repository>
   <id>objectdb</id>
   <name>ObjectDB Repository</name>
   <url>https://m2.objectdb.com</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
   <groupId>com.objectdb</groupId>
   <artifactId>objectdb</artifactId>
   <version>2.8.1</version>
  </dependency>
 <dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>javax.persistence</artifactId>
    <version>2.1.0</version>
  </dependency>
  <dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>jta</artifactId>
    <version>1.1</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>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>3.0.5.RELEASE</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-tx</artifactId>
   <version>3.0.5.RELEASE</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-orm</artifactId>
   <version>3.0.5.RELEASE</version>
  </dependency>
  <dependency>
   <groupId>aopalliance</groupId>
   <artifactId>aopalliance</artifactId>
   <version>1.0</version>
  </dependency>
  <dependency>
   <groupId>cglib</groupId>
   <artifactId>cglib</artifactId>
   <version>2.2</version>
  </dependency>
  <dependency>
   <groupId>org.aspectj</groupId>
   <artifactId>aspectjweaver</artifactId>
   <version>1.6.10</version>
  </dependency>
</dependencies>

<build>
  <pluginManagement>
   <plugins>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <configuration>
      <source>1.7</source>
      <target>1.7</target>
     </configuration>
    </plugin>
    <plugin>
     <groupId>org.codehaus.mojo</groupId>
     <artifactId>exec-maven-plugin</artifactId>
     <version>1.2</version>
     <executions>
      <execution>
       <id>enhance</id>
       <phase>process-classes</phase>
       <goals>
        <goal>java</goal>
       </goals>
       <configuration>
        <mainClass>com.objectdb.Enhancer</mainClass>
        <arguments>
         <argument>guest.Guest</argument>
        </arguments>
       </configuration>
      </execution>
     </executions>
    </plugin>
    <plugin>
     <groupId>org.mortbay.jetty</groupId>
     <artifactId>maven-jetty-plugin</artifactId>
     <version>6.1.10</version>
     <configuration>
      <scanIntervalSeconds>10</scanIntervalSeconds>
      <stopKey>foo</stopKey>
      <stopPort>9999</stopPort>
     </configuration>
     <executions>
      <execution>
       <id>start-jetty</id>
       <phase>pre-integration-test</phase>
       <goals>
        <goal>run</goal>
       </goals>
       <configuration>
        <scanIntervalSeconds>0</scanIntervalSeconds>
        <daemon>true</daemon>
       </configuration>
      </execution>
      <execution>
       <id>stop-jetty</id>
       <phase>post-integration-test</phase>
       <goals>
        <goal>stop</goal>
       </goals>
      </execution>
     </executions>
    </plugin>
   </plugins>
  </pluginManagement>
  <finalName>Guestbook</finalName>
</build>

</project>

Now you should have a Maven based Eclipse dynamic web project (WTP) with Spring MVC Framework and ObjectDB/JPA support.

The next step is creating a JPA Entity class.