10 Building Java EE Projects for WebLogic Server with Maven
Topics:
- Introduction to Building a Java EE Project with Maven
A Maven plug-in and four archetypes are provided for Oracle WebLogic Server. - Using the Basic WebApp Maven Archetype
To build a Java EE project using the basic WebApp Maven archetype, you create the basic project, then customize, compile and package it. Then you deploy it and test it. - Using the Basic WebApp with EJB Maven Archetype
To build a Java EE project using the basic WebApp with EJB Maven archetype, you create the basic project, then customize, compile and package it. Then you deploy it and test it. - Using the Basic WebService Maven Archetype
To build a Java EE project using the basic WebService Maven archetype, you create the basic project, then customize, compile and package it. Then you deploy it and test it. - Using the Basic MDB Maven Archetype
To build a Java EE project using the basic MDB Maven archetype, you create the basic project, then customize, compile and package it. Then you deploy it and test it.
Introduction to Building a Java EE Project with Maven
A Maven plug-in and four archetypes are provided for Oracle WebLogic Server.
Table 10-1 describes the Maven coordinates.
Table 10-1 Maven Coordinates with WebLogic Server
Artifact | groupId | artifactId | version |
---|---|---|---|
WebLogic Server plug-in |
|
|
|
Basic WebApp archetype |
|
|
|
WebApp with EJB archetype |
|
|
|
Basic MDB archetype |
|
|
|
Basic WebServices archetype |
|
|
|
As with Maven archetypes in general, the Oracle WebLogic Maven archetype provides a set of starting points and examples for building your own applications.
Parent topic: Building Java EE Projects for WebLogic Server with Maven
Using the Basic WebApp Maven Archetype
To build a Java EE project using the basic WebApp Maven archetype, you create the basic project, then customize, compile and package it. Then you deploy it and test it.
This section contains the following topics:
- Creating a Basic WebApp Project
- Customizing the Project Object Model File to Suit Your Environment
- Compiling Your Java EE Project
- Packaging Your Java EE Project
- Deploying Your Java EE Project to the WebLogic Server Using Maven
- Deploying Your Java EE Project to the WebLogic Server Using Different Options
- Testing Your Basic WebApp Project
Parent topic: Building Java EE Projects for WebLogic Server with Maven
Creating a Basic WebApp Project
To create a new Basic WebApp project using the Maven archetype, you must issue a command similar to the following:
mvn archetype:generate -DarchetypeGroupId=com.oracle.weblogic.archetype -DarchetypeArtifactId=basic-webapp -DarchetypeVersion=12.2.1-0-0 -DgroupId=org.mycompany -DartifactId=my-basic-webapp-project -Dversion=1.0-SNAPSHOT
This command runs Maven's archetype:generate
goal which enables you to create a new project from an archetype. Table 10-2 describes the parameters.
Table 10-2 Parameters for the Basic WebApp Project
Parameter | Purpose |
---|---|
|
The group ID of the archetype that you want to use to create the new project. This must be |
|
The archetype artifact ID of the archetype that you want to use to create the new project. This must be |
|
The version of the archetype that you want to use to create the new project. This must be 12.2.1-0-0 as shown in the preceding example. |
|
The group ID for your new project. This usually starts with your organization's domain name in reverse format. |
|
The artifact ID for your new project. This is usually an identifier for this project. |
|
The version number for your new project. This is usually |
You can also run the command without any arguments, as shown in the following example. In this case, Maven displays a list of available archetypes and prompts you to enter the required information.
mvn archetype:generate
If you want to limit Maven to look only into a particular repository, you can specify the -DarchetypeCatalog
option. Specify the value as local
to look only in your local repository, or specify the serverId
for the repository you want Maven to look in. This limits the number of archetypes that you are shown and makes the command execute much faster.
After creating your project, it contains the following files:
These files make up a small sample application, which you can deploy as is. You can use this application as a starting point for building your own application.
Table 10-3 describes the files included in the project.
Table 10-3 Files Created for the Basic WebApp project
File | Purpose |
---|---|
|
The Maven Project Object Model (POM) file that describes your new project. It includes the Maven coordinates that you specified for your project. It also includes the appropriate plug-in definitions needed to use the WebLogic Maven plug-in to build your project. |
Files under |
An example Enterprise Java Bean that is used by the Web application to store data. |
All other files |
HTML and other files that make up the web application user interface. |
After you have written your project code, you can use Maven to build the project. It is also possible to build the sample as is.
Parent topic: Using the Basic WebApp Maven Archetype
Customizing the Project Object Model File to Suit Your Environment
The Project Object Model (POM) file that is created by the archetype is sufficient in most cases. Review the POM and update any of the settings where the provided default values differ from what you use in your environment.
If you are using an internal Maven Repository Manager, like Archiva, add a pluginRepository
to the POM file. The following is an example; you can modify it to suit your environment:
<pluginRepositories> <pluginRepository> <id>archiva-internal</id> <name>Archiva Managed Internal Repository</name> <url>http://localhost:8081/archiva/repository/internal/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories>
Parent topic: Using the Basic WebApp Maven Archetype
Compiling Your Java EE Project
To compile the source code in your project, such as Java Beans, Servlets, and JSPs, use the following command:
mvn compile
This command uses the standard Maven plug-ins to compile your source artifacts into class files. You can find the class files in the target
directory of your project.
Parent topic: Using the Basic WebApp Maven Archetype
Packaging Your Java EE Project
To build the deployment archive, for example WAR or EAR file, use the following command:
mvn package
This command uses the standard Maven plug-ins to package your compiled artifacts and metadata into a deployment archive. When you run a Maven goal like package
, Maven runs not just that goal, but all of the goals up to and including the goal you name. This is very similar to a standard Java EE application, except that if you have WebLogic deployment descriptors in your project, they are also packaged into the deployment archive.
The deployment archive, in this case a WAR file, is available in the target
directory of your project.
Parent topic: Using the Basic WebApp Maven Archetype
Deploying Your Java EE Project to the WebLogic Server Using Maven
To deploy the deployment archive using Maven, use the following command:
mvn pre-integration-test
This command executes the deploy
goal in the WebLogic Maven plug-in. This goal supports all standard types of deployment archives.
Parent topic: Using the Basic WebApp Maven Archetype
Deploying Your Java EE Project to the WebLogic Server Using Different Options
After you have packaged your project, you can also deploy it to the WebLogic Server using any of the other existing (non-Maven) mechanisms. For example, the WebLogic Administration Console, or an ANT or WLST script.
Parent topic: Using the Basic WebApp Maven Archetype
Testing Your Basic WebApp Project
You can test the Basic WebApp by visiting the following URL on the WebLogic Server where you deployed it:
Parent topic: Using the Basic WebApp Maven Archetype
Using the Basic WebApp with EJB Maven Archetype
To build a Java EE project using the basic WebApp with EJB Maven archetype, you create the basic project, then customize, compile and package it. Then you deploy it and test it.
To use the Basic WebApp with EJB project using the Maven archetype:
Parent topic: Building Java EE Projects for WebLogic Server with Maven
Using the Basic WebService Maven Archetype
To build a Java EE project using the basic WebService Maven archetype, you create the basic project, then customize, compile and package it. Then you deploy it and test it.
To use the Basic WebService project using the Maven Archetype:
Parent topic: Building Java EE Projects for WebLogic Server with Maven
Using the Basic MDB Maven Archetype
To build a Java EE project using the basic MDB Maven archetype, you create the basic project, then customize, compile and package it. Then you deploy it and test it.
To use the Basic MDB project using the Maven Archetype:
Parent topic: Building Java EE Projects for WebLogic Server with Maven