Technical Note

Developing a Project with Oracle JDeveloper 10g and the Maven Plugin

Author: Deepak Vohra (dvohra09@yahoo.com), Web Developer and Sun Certified Java 1.4 programmer
Publication Date: October 2004

Maven is an open-source project development tool from the Apache Jakarta Project for building and managing Java projects; it integrates the capabilities of other open source development lifecycle tools such as Ant, Junit, and Jelly. A Maven project consists of a J2EE project file or an IDE-specific project file--for example a JDeveloper project file (JPR file).

Maven has some advantages over Apache Ant, the standard build tool for Java projects. In addition to the project build features, which are similar to those of Ant, Maven provides project management facilities.

Maven is based on the Project Object Model, and all the project components are constructed from a project model. The Maven Plugin for Oracle JDeveloper 10g (Oracle uses the term "extension") is used to generate JDeveloper project files (.jpr). The plugin defines a set of goals that are semantically similar to the targets in the Ant build tool. The plugin comprises:

  • A project configuration file (project.xml) to define the project model
  • A project.properties file to specify the project properties
  • A plugin.jelly file to specify the different goals of the project
  • A plugin.properties file to specify the plugin properties
  • A JavaSourceTool.class class to generate java source directories.
In this Technical Note you will learn how to develop a JDeveloper (Java application) project with the Maven JDeveloper Plugin and then import the project into the JDeveloper IDE. A JUnit test for the application is also included in the project.

Preliminary Setup

The Maven project tool is required to develop a JDeveloper project with the Maven JDeveloper plugin. Maven 1.0 may be obtained as a zip file, a .exe application, a tar.bz2 file, or a tar.gz file. Here are our setup steps:

  1. Download and extract the maven-1.0 zip file to an installation directory.
  2. Set the MAVEN_HOME variable to the value of the Maven installation directory; for example C:/Maven/maven-1.0.
  3. Add %MAVEN_HOME%/bin to the %PATH% variable.
  4. Download the Maven JDeveloper plugin maven-jdeveloper-plugin-1.4.jar.
  5. Copy the plugin to the %MAVEN_HOME%/plugins directory (if it is not already there).
  6. Download the JUnit testing tool and extract the junit3.8.1.zip file to a directory.
  7. Download and install Oracle JDeveloper 10g.
Generating a JDeveloper Project in Maven

As discussed above, the Maven JDeveloper plugin defines a set of goals that may be run to generate the JDeveloper project files. The JDeveloper plugin defines the jdeveloper:genererate-project and jdeveloper:scanSources goals. The plugin goals may be listed with the command:

>maven -g 
The JDeveloper plugin goals are then listed:
[jdeveloper]                  Generate JDeveloper project files
  generate-project  ......... Generate jdeveloper .jpr
  scanSources  .............. Scans the source in order to integrate them
                              into JDeveloper files
The plugin goals are configured in the plugin.jelly configuration file. The project properties are defined in the plugin.properties file.
maven.jdeveloper.workspache=WPS
maven.jdeveloper.relative.path=../
maven.jdeveloper.maven.home=Maven/maven-1.0
The maven.jdeveloper.workspace property specifies the JDeveloper workspace to which the project belongs. maven.jdeveloper.relative.path property specifies the relative path to the %MAVEN_HOME% directory from the JDeveloper installation directory. maven.jdeveloper.maven.home property specifies the %MAVEN_HOME% directory.

The project model for a JDeveloper project is defined in the project.xml configuration file. (See the sample code download.) The project management section of project.xml specifies information about the project's developer list and location of source code. The project dependency section specifies the jar files on which the project depends. The project build section specifies the project source directory and the project JUnit test source directory.

Modify the project.xml file to add the sourceDirectory, unitTestSourceDirectory, and unitTest elements. The sourceDirectory element specifies the directory for the project source files. The unitTestSourceDirectory specifies the directory for the JUnit test files. The unitTest element specifies the files to include/exclude from the JUnit test, and the resources associated with the JUnit test.

The project.xml configuration file is based on the maven-project.xsd schema. Some of the elements in the project.xml file are explained below.

Element Description
project The root element of the project descriptor specifies the various project attributes.
extend The project.xml that is extended by the current project.xml
pomVersion The version of the Maven project descriptor
siteDirectory The public web site directory for the project
repository Specifies the source configuration management system used by the project
developers Specifies the project developers
dependencies Specifies the project dependencies, which are downloaded by Maven to a local repository
build Specifies the build environment for the project
versions Specifies each of the previous versions of the project

Now, let's build the example Java application, Catalog.java. (See sample code download.) Catalog.java is copied to the Maven/src/java directory, which is defined as the <sourceDirectory/> in the project.xml. Next, create a JUnit test file to test the application. In the JUnit test, import the JUnit classes:

import junit.framework.*;
The test class extends the TestCase class. Define a test method testJournal to test the Java application. The JUnit test class may consist of additional test methods. Define a suite method that creates a test suite of all the test methods. Run the test with the text test runner.
junit.textui.TestRunner.run(suite());
The test class JunitTest.java is available in the sample code download. Copy the JunitTest class to the Maven/JUnit/test directory, which is the <UnitTestSourceDirectory> in project.xml.

To generate a JDeveloper project from the Java application and the JUnit test, run the JDeveloper plugin goals. First, run the scanSources goal with the command:

C:/Maven>maven jdeveloper:scanSources
Next, run the generate-project goal with the command:
C:/Maven>maven jdeveloper:generate-project
A JDeveloper project Global Project.jpr is generated.

In the next section, we'll load the project into JDeveloper.

Configuring a Maven-Generated Project in JDeveloper

We'll need to open the JDeveloper project Global Project.jpr generated with the Maven JDeveloper plugin in JDeveloper 10g. First, start JDeveloper.

figure 1
Figure 1: Oracle JDeveloper 10g

Select File>New to configure a new workspace. Select General>Workspaces in the Categories listed in the New Gallery frame. Select Workspace in the Items listed.

figure 2
Figure 2: General>Workspaces>Workspace

Specify a Workspace Name in the Create Workspace frame. In the Create Project frame, do not configure a Project, because the project generated with the Maven JDeveloper plugin will be imported later. A workspace is configured in the Applications-Navigator.

figure 3
Figure 3: Applications>Workspace

To deploy the Global Project.jpr generated with the Maven JDeveloper plugin, select File>Open in JDeveloper. Select Global Project.jpr in the open frame.

figure 4
Figure 4: Open Global Project.jpr

The Global Project.jpr is added to JDeveloper.

figure 5
Figure 5: Applications>WPS>Global Project

To run the JUnit test the JUnit classes are required in the classpath. Select Tools>Project Properties to configure the project properties.

figure 6
Figure 6: Tools>Project Properties

Select Profiles>Development>Paths in the Project Properties frame. Add junit.jar to the Additional Classpath field.

figure 7
Figure 7: Adding JUnit classes to classpath

To run the Java application Catalog.java, right-click on Catalog.java and select Run.

figure 8
Figure 8: Running Catalog.java

The output from the Java application is produced in the Messages frame.

figure 9
Figure 9: Output from the Java application

To run the JUnit test, right-click on the test class and select Run.

figure 10
Figure 10: Running the JUnit test

The output from the JUnit test is produced in the Messages frame.

figure 11
Figure 11: Output from JUnit test

You have just created a sample application project using the Maven JDeveloper plugin and imported it into JDeveloper.


Resources
Oracle JDeveloper How-To's
Java Developer Center
Open Source Developer Center
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy