Working With Maven Projects In Oracle JDeveloper
An Oracle JDeveloper How To Document
Written by Dana Singleterry,
Oracle Corporation
Updated December 2007
Introduction
Required Software
Downloading
and Installing Maven 2.0.7
Downloading
and Installing the Maven JDeveloper Plugin
Downloading
the Trinidad Source Using Subversion Integration with JDeveloper
Install Trinidad
Run
Maven from
within JDeveloper to Create a JDeveloper Workspace (.jws) and Project
(.jpr)
Adding
Code Insight for pom.xml
Run the
Trinidad Demo Application
Conclusion
This document
explains how-to work with Oracle JDeveloper on Maven-based projects. As
an example we'll use the MyFaces Trinidad project code,
and
utilize the Maven
2.0.7 distribution and the Maven plugin for Oracle
JDeveloper to create a JDeveloper project that will allow us
to
view the sources
and run the application.
NEW!
You can also work through this tutorial utilizing JDeveloper
11 TP3 and the Maven
JDeveloper Plugin 1.2.5.
Introduction
Maven is a software project management and comprehension
tool. Based on the concept of a project object model (POM), Maven can
manage a project's build, reporting and documentation from a central
piece of information.
Maven's primary goal is to allow a developer to
comprehend the
complete state of a development effort in the shortest period of time.
In order to attain this goal there are several areas of concern that
Maven attempts to deal with:
- Making the build process easy
- Providing a uniform build system
- Providing quality project information
- Providing guidelines for best practices development
- Allowing transparent migration to new features
Much
of Maven's power comes from the standard practices it
encourages. Time
need not be wasted reinventing directory structures, conventions, and
customized Ant build scripts for each project. Although you can
override any particular directory location for your own specific needs,
it's best to stick with the standard Maven 2 directory
structure
as
much as possible, for several reasons:
- It makes your POM file smaller and simpler
- It makes the project easier to understand
- It makes it easier to integrate plug-ins
The standard Maven 2 directory structure is illustrated
here. In the project home directory goes the POM (pom.xml) and two
subdirectories: src for all source code and target for generated
artifacts.

The src directory has a number of subdirectories, each
of which has a clearly defined purpose:
- src/main/java: Your Java
source code goes here (strangely enough!)
- src/main/resources:
Other resources your application needs
- src/main/filters:
Resource filters, in the form of properties files, which may be used to
define variables only known at runtime
- src/main/config:
Configuration files
- src/main/webapp: The Web
application directory for a WAR project
- src/test/java: Unit
tests
- src/test/resources:
Resources to be used for unit tests, but will not be deployed
- src/test/filters:
Resources filters to be used for unit tests, but will not be deployed
- src/site: Files used to
generate the Maven project Website
Required
Software
JDeveloper
10.1.3.3 J2EE or Studio Edition
Maven
2.0.7
Maven
JDeveloper Plugin (1.2.0-7-may-snapshot)
Trinidad
Source
Java
JDK 1.5
If using JDeveloper 11 TP3 and the Maven JDeveloper Plugin 1.2.5, then
substitute the JDeveloper and Maven plugin above with the following:
JDeveloper
11 TP3 Studio or Base Edition
Maven
JDeveloper Plugin 1.2.5
Downloading
and Installing Maven 2.0.7
Download
the appropriate Maven 2.0.7 distribution and install as follows for
Windows 2000/XP:
- Unzip maven-2.0.7-bin.zip to
the directory you wish to install Maven 2.0.7. These instructions
assume you chose C:\Program Files\Apache Software
Foundation\maven-2.0.7
- Add the bin
directory to your path, by opening up the system properties (WinKey +
Pause), selecting the "Advanced" tab, and the "Environment Variables"
button, then editing the PATH variable in the
user variables. e.g. "C:\Program Files\Apache Software
Foundation\maven-2.0.7\bin";%PATH%
- In the same dialog, make sure that JAVA_HOME
is set to the location of your JDK, e.g. C:\Program
Files\Java\jdk1.5.0_02
- Run mvn --version to verify
that it is correctly installed.
- To create the Maven repository, you select the /bin
directory of the Maven download and type mvn install.
Note that if your Internet access is through a firewall, you need to
create an additional configuration file (settings.xml) as explained in
the documentation.
To create the Maven repository, select the /bin directory of
the Maven download and run mvn
install.
Downloading
and Installing the Maven JDeveloper Plugin
The Maven Plugin for Oracle JDeveloper 10g
is used to generate JDeveloper workspace files (.jws) and 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.
To use the Maven JDeveloper
Plugin, complete the following steps:
- Download
the Maven JDeveloper Plugin jar (1.2.0-7-may-snapshot) and
corresponding .pom file.
- Copy the plugin and pom to your maven repository that
you created previously.
For example, if your Maven repository was created in
the following
location:
C:\{RepositoryHome}\.m2\repository\org\apache\myfaces\trinidadbuild\maven-jdev-plugin\1.2-07-may-SNAPSHOT
Copy both maven-jdev-plugin-1.2-07-may-SNAPSHOT.pom
and maven-jdev-plugin-1.2-07-may-SNAPSHOT.jar
as indicated above.
Downloading
the Trinidad Source Using SubVersion Integration with JDeveloper
To demonstrate the process of working with the Maven
JDeveloper plugin we'll use the source for the apache MyFaces Trinidad
project.
The Trinidad JSF sources are available from the
subversion source control (http://svn.apache.org/repos/asf/myfaces/trinidad/trunk).
You can check out the sources anyway you want. One way is to download
and use Tortoise,
another to use the JDeveloper Subversion Extension. In this how-to The
JDeveloper Subversion extension will be used.
Note: When you check out the
Trinidad source to your local file system,
the
sources should be stored on the same drive as the maven installation.
The JDeveloper Subversion VCS
extension is available via the official
Oracle update center. You install updates using the Check for Updates
feature available from the Help menu.

Using the Check
for
Updates wizard.

Search the Official
Oracle Extensions and Updates center.

Locate and select the Subversion
VCS Extension entry. Selecting this will
automatically select the VCS Framework Extension update too.
For further details on
working with Subversion please see the Using
JDeveloper with Subversion How-to.
Now that you've installed the
Subversion for JDeveloper Extension you
can create a new SubVersion repository connection.

First select subversion as your versioning system by
selecting the Versioning
menu
followed by Subversion
from the Select Version
System submenu.

If the Subversion
Navigator is not visible then select it from the View menu.

Right select Subversion
from within the Subversion
Navigator and create a New
Repository Connection.

Enter an appropriate name (i.e. trinidadrepos) for
the repository
connection. Enter the following credentials and test the connection to
ensure access. Note: You are using anonymous access.

Right select the repository connection you just
created, trinidadrepos,
from
within the Subversion
Navigator and select the submenu Check Out.

Keep in mind
that the repository must be stored on the same volume as the Maven
installation.

The results of your checkout can be viewed in the Messages-Log.

You can also explore the repository you check out
from within Windows
Explorer.
Install
Trinidad
To install trinidad that you
previously downloaded, perform the
following steps in a command window.
- Ensure the Maven JDeveloper Plugin has been copied to
the C:\trinidadrepos\plugins directory if it's not already there.
- cd trinidad/plugins
mvn install
- cd ../trinidad
mvn install
With mvn install you create
the jar files that are stored in the M2
repository.

Results of successfully building plugins.

Results of successfully building trinidad source.

After installing the Trinidad sources, the Maven
repository m2
in the Documents and Settings
directory contains the source code and a demo WAR file that you can
deploy to your J2EE container to see the Trinidad components in action.
What we'll demonstrate here
instead is creating a JDeveloper workspace
and a project through the use of the Maven JDeveloper plugin
that we
built in a previous step so that we can view the trinidad source and
run the trinidad demos from within JDevelopers embedded server.
You're now ready to create
your JDeveloper Workspace (.jws) and Project
(.jpr) so that you can work with your project in JDeveloper.
Run
Maven from within JDeveloper to Create a JDeveloper Workspace (.jws)
and Project (.jpr)
While the Maven JDeveloper
plugin can be invoked from a command line,
it can be useful to run Maven from inside Oracle JDeveloper so that
running Maven does not require launching a new command window.
The following demonstrates how to configure the maven
distribution goal and add a new menu option in Oracle JDeveloper to
invoke
the Maven goal to create your workspace and projects.

Begin
the process by choosing External
Tools in the Tools menu.

Select New
from the External Tools
Wizard.

Select External
Program
for Tool Type.

Enter the credentials above for Program
Executable, Arguments,
and Run Directory
within the wizard for Step
2of 5: External Program Options.

Select Insert
button for Run Directory
within the wizard in Step
2of 5 and select Prompt
with Label and enter an appropriate Label as a hint.

Select Next.

Enter the credentials above for Caption
for Menu Items and ToolTip
Text within the wizard for Step 3 of 5: Display.
Keep the default for Icon
Location. Select Finish.

The New External Tools item of MvnGoal
has now been created.

The new MvnGoal
tool is now available in the Tools
menu within JDeveloper. Select it to run the specified External Tool
that has been created.

Results of running the MvnGoal
from within JDeveloper.
Adding
Code Insight for pom.xml in JDeveloper
Code insight can be added
within JDeveloper for the pom.xml by
downloading the maven-xsd
and registering it with JDeveloper as follows:
- Download the maven-xsd
- Register the maven-xsd with JDeveloper under
tools->preferences->xml schemas as illustrated here.

Select the Tools
menu followed by the Preferences
sub-menu.

Select XML
Schemas.

Select Add
and browse for the maven-xsd
you downloaded previously and select OK once complete.

Select OK.
You've now successfully added code insight.
In order to utilize code
insight within your pom.xml
file, the
pom.xml file you create must have the following header:
<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">
... </project>
With this header in your
pom.xml file, code insight as well as the
ability to work from the component palette, property palette and
structure pane with the pom.xml will be available.

After opening the pom.xml
for the trinidad project we see that it's available in the Structure pane. You
can explore elements and work with them in the Property Inspector and
also see code insight in action by adding another mailingList element
for example.
Run
the Trinidad Demo Application
Now that the JDeveloper
Workspace and JDeveloper Projects have been
created for the Trinidad Demo Application, the workspace can be opened
within JDeveloper and browsed as well ad running the demos from within
the JDeveloper Embedded Server as demonstrated.

Open the Trinidad workspace,
trinidad.jws, from within the trinidad checkout directory.

Browse the various trinidad projects.

Open the trinidad-demo
project.

Right select the index.jspx
page and select Run
to run the demos within the Oracle JDeveloper embedded server.

Trinidad demos running within the Oracle JDeveloper
embedded server.
Conclusion
Maven is
a powerful build tool with many unique capabilities. The Maven
JDeveloper plugin provides an easy way to use JDeveloper with Maven
based projects.
For further
information on Oracle JDeveloper, Maven,
and Trinidad please visit the following sites.
Oracle
JDeveloper
Maven
Trinidad
Using
JDeveloper with Subversion (Oracle How-To)
How-To
configure Apache Trinidad components in Oracle JDeveloper
JDeveloper:
Using Trinidad JSF components in JDeveloper
Managing
J2EE Projects
|