Fusion Middleware Documentation
Advanced Search


Developing Applications Using Continuous Integration
Close Window

Table of Contents

Show All | Collapse

9 Building Java EE Projects for WebLogic Server with Maven

This chapter provides details on how to use the WebLogic Maven archetypes to create, build, and deploy WebLogic Server Java EE applications.

This chapter contains the following sections:

9.1 Introduction to Building Java EE Project with Maven

A Maven plug-in and four archetypes are provided for Oracle WebLogic Server. The Maven coordinates are described inTable 9-1.

Table 9-1 Maven Coordinates with WebLogic Server

Artifact groupId artifactId version

WebLogic Server plug-in

com.oracle.weblogic

weblogic-maven-plugin

12.1.2-0-0

Basic WebApp archetype

com.oracle.weblogic.archetype

basic-webapp

12.1.2-0-0

WebApp with EJB archetype

com.oracle.weblogic.archetype

basic-webapp-ejb

12.1.2-0-0

Basic MDB archetype

com.oracle.weblogic.archetype

basic-mdb

12.1.2-0-0

Basic WebServices archetype

com.oracle.weblogic.archetype

basic-webservice

12.1.2-0-0


As with Maven archetypes in general, the Oracle WebLogic Maven archetype provides a set of starting points and examples for building your own applications.

9.2 Using the Basic WebApp Maven Archetype

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.1.2-0-0
    -DgroupId=org.mycompany
    -DartifactId=my-basic-webapp-project
    -Dversion=1.0-SNAPSHOT

This runs Maven's archetype:generate goal which enables you to create a new project from an archetype. The parameters are described in Table 9-2.

Table 9-2 Parameters for the Basic WebApp Project

Parameter Purpose

archetypeGroupId

Identifies the groupId of the archetype that you wish to use to create the new project. This must be com.oracle.weblogic as shown in the preceding example.

archetypeArtifactId

Identifies the artifactId of the archetype that you wish to use to create the new project. This must be basic-webapp as shown in the preceding example.

archetypeVersion

Identifies the version of the archetype that you wish to use to create the new project. This must be 12.1.2-0-0 as shown in the preceding example.

groupId

Identifies the groupId for your new project. This would normally start with your organization's domain name in reverse format.

artifactId

Identifies the artifactId for your new project. This would normally be an identifier for this project.

version

Identifies the version number for your new project. This would normally be 1.0-SNAPSHOT for a new project.


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 will limit the number of archetypes that you are shown and make the command execute much faster.

After creating your project, it will contain the following files:

Description of basic_webapp_maven1.gif follows
Description of the illustration basic_webapp_maven1.gif

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.

There are a number of files included in the project, as described in Table 9-3.

Table 9-3 Files Created for the Basic WebApp project

File Purpose

pom.xml

The Maven Project Object Model (POM) file that describes your new project. It includes the Maven coordinates that you specified for your project, and it also includes the appropriate plug-in definitions to use the WebLogic Maven Plug-in to build your project.

Files under src/main/java

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.

This section contains the following topics:

9.2.1 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. You should 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, you should 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>

9.2.2 Compiling Your Project

To compile the source code in your project, such as Java Beans, Servlets, and JSPs, use the following command:

mvn compile

This 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.

9.2.3 Packaging Your Project

To build the deployment archive, for example WAR or EAR file, use the following command:

mvn package

Again, this 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 some 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.

9.2.4 Deploying Your Project to the WebLogic Server Using Maven

To deploy the deployment archive using Maven, use the following command:

mvn pre-integration-test

This executes the deploy goal in the WebLogic Maven Plug-in. This goal supports all standard types of deployment archives.

9.2.5 Deploying Your 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.

9.2.6 Testing Your Basic WebApp Project

You can test the Basic WebApp by visiting the following URL on the WebLogic Server where you deployed it:

http://servername:7001/basicWebapp/index.xhtml

The user interface for the Basic WebApp looks like this:

Description of wls_02.jpg follows
Description of the illustration wls_02.jpg

Provide the Account Name and Amount, then select Deposit to see how the application works.

9.3 Using the Basic WebApp with EJB Maven Archetype

To use the Basic WebApp with EJB project using the Maven Archetype:

  1. 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-ejb
        -DarchetypeVersion=12.1.2-0-0
        -DgroupId=org.mycompany
        -DartifactId=my-basic-webapp-ejb-project
        -Dversion=1.0-SNAPSHOT
    

    This runs Maven's archetype:generate goal which enables you to create a new project from an archetype. See Table 9-4 for a description of the parameters.

    Table 9-4 Parameters for the Basic WebApp with EJB Project

    Parameter Purpose

    archetypeGroupId

    Identifies the groupId of the archetype that you wish to use to create the new project. This must be com.oracle.weblogic as shown in the preceding example.

    archetypeArtifactId

    Identifies the artifactId of the archetype that you wish to use to create the new project. This must be basic-webapp-ejb as shown in the preceding example.

    archetypeVersion

    Identifies the version of the archetype that you wish to use to create the new project. This must be 12.1.2-0-0 as shown in the preceding example.

    groupId

    Identifies the groupId for your new project. This would normally start with your organization's domain name in reverse format.

    artifactId

    Identifies the artifactId for your new project. This would normally be an identifier for this project.

    version

    Identifies the version number for your new project. This would normally be 1.0-SNAPSHOT for a new project.


    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
    

    After creating your project, it will contain the following files:

    Description of basic_webapp_ejb_maven2.gif follows
    Description of the illustration basic_webapp_ejb_maven2.gif

    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.

    There are a number of files included in the project, the purpose of each file is described in Table 9-5.

    Table 9-5 Files Created for the Basic WebApp with EJB Project

    File Purpose

    pom.xml

    The Maven Project Object Model (POM) file that describes your new project. It includes the Maven coordinates that you specified for your project, and it also includes the appropriate plug-in definitions to use the WebLogic Maven Plug-in to build your project.

    Files under src/main/java

    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.


  2. 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.

  3. Customize the POM to suit your environment. See Section 9.2.1.

  4. Compile your Basic WebApp with EJB Project. See Section 9.2.2.

  5. Package your Basic WebApp with EJB Project. See Section 9.2.3.

  6. Deploy your Basic WebApp with EJB Project. For information about deploying it using Maven, see Section 9.2.4. For information about deploying it using other options, see Section 9.2.5.

  7. Test your Basic WebApp with EJB Project.

    You can test the Basic WebApp with EJB by visiting the following URL on the WebLogic Server where you deployed it:

    http://servername:7001/basicWebapp/index.xhtml
    

    The user interface for the Basic WebApp with EJB looks like this:

    Description of wls_04.jpg follows
    Description of the illustration wls_04.jpg

    Provide the Account Name and Amount, then select Deposit to see how the application works.

9.4 Using the Basic WebService Maven Archetype

To use the Basic WebService project using the Maven Archetype:

  1. Create a new Basic WebService project using the Maven archetype, you must issue a command similar to the following:

    mvn archetype:generate
        -DarchetypeGroupId=com.oracle.weblogic.archetype
        -DarchetypeArtifactId=basic-webservice
        -DarchetypeVersion=12.1.2-0-0
        -DgroupId=org.mycompany
        -DartifactId=my-basic-webservice-project
        -Dversion=1.0-SNAPSHOT
    

    This runs Maven's archetype:generate goal which enables you to create a new project from an archetype. See Table 9-6 for the parameters and description.

    Table 9-6 Parameters for the Basic WebService Project

    Parameter Purpose

    archetypeGroupId

    Identifies the groupId of the archetype that you wish to use to create the new project. This must be com.oracle.weblogic as shown in the preceding example.

    archetypeArtifactId

    Identifies the artifactId of the archetype that you wish to use to create the new project. This must be basic-webservice as shown in the preceding example.

    archetypeVersion

    Identifies the version of the archetype that you wish to use to create the new project. This must be 12.1.2-0-0 as shown in the preceding example.

    groupId

    Identifies the groupId for your new project. This would normally start with your organization's domain name in reverse format.

    artifactId

    Identifies the artifactId for your new project. This would normally be an identifier for this project.

    version

    Identifies the version number for your new project. This would normally be 1.0-SNAPSHOT for a new project.


    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
    

    After creating your project, it will contain the following files:

    Description of basic_webservice_maven3.gif follows
    Description of the illustration basic_webservice_maven3.gif

    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.

    There are a number of files included in the project, see Table 9-7 for the purpose of each file.

    Table 9-7 Files created for the Basic WebService Project

    File Purpose

    pom.xml

    The Maven Project Object Model (POM) file that describes your new project. It includes the Maven coordinates that you specified for your project, and it also includes the appropriate plug-in definitions to use the WebLogic Maven Plug-in to build your project.

    SayHello.java

    An example Web Service.


  2. 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.

  3. Customize the POM to suit your environment. See Section 9.2.1.

  4. Compile your Basic WebService Project. See Section 9.2.2.

  5. Package your Basic WebService Project. See Section 9.2.3.

  6. Deploy your Basic WebService Project. For information about deploying it using Maven, see Section 9.2.4. For information about deploying it using other options, see Section 9.2.5.

  7. Test your Basic WebService Project.

    You can test the Basic WebService by visiting the following URL, on the WebLogic Server where you have deployed it:

    http://servername:7001/basicWebservice/SayHello
    

    The user interface for the Basic WebService looks like the following:

    Description of wls_06.jpg follows
    Description of the illustration wls_06.jpg

    You can access the WSDL for the web service, and you can open the WebLogic Web Services Test Client by selecting the Test link. This enables you to invoke the web service and observe the output.

    To test the web service, select SayHello operation in the left hand pane, then enter a value for arg0 as shown in the following example, and select Invoke.

    Description of wls_08.jpg follows
    Description of the illustration wls_08.jpg

    Scroll down to see the test results, as shown in the following example:

    Description of wls_10.jpg follows
    Description of the illustration wls_10.jpg

9.5 Using the Basic MDB Maven Archetype

To use the Basic MDB project using the Maven Archetype:

  1. Create a new Basic MDB project using the Maven archetype, by running a command similar to the following:

    mvn archetype:generate
        -DarchetypeGroupId=com.oracle.weblogic.archtype
        -DarchetypeArtifactId=basic-mdb
        -DarchetypeVersion=12.1.2-0-0
        -DgroupId=org.mycompany
        -DartifactId=my-basic-mdb-project
        -Dversion=1.0-SNAPSHOT
    

    This runs Maven's archetype:generate goal which enables you to create a new project from an archetype. See Table 9-8 for the parameters and description.

    Table 9-8 Parameters for the Basic MDB Project

    Parameter Purpose

    archetypeGroupId

    Identifies the groupId of the archetype that you wish to use to create the new project. This must be com.oracle.weblogic as shown in the preceding example.

    archetypeArtifactId

    Identifies the artifactId of the archetype that you wish to use to create the new project. This must be basic-mdb as shown in the preceding example.

    archetypeVersion

    Identifies the version of the archetype that you wish to use to create the new project. This must be 12.1.2-0-0 as shown in the preceding example.

    groupId

    Identifies the groupId for your new project. This would normally start with your organization's domain name in reverse format.

    artifactId

    Identifies the artifactId for your new project. This would normally be an identifier for this project.

    version

    Identifies the version number for your new project. This would normally be 1.0-SNAPSHOT for a new project.


    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
    

    After creating your project, it will contain the following files:

    Description of basic_mdb_maven4.gif follows
    Description of the illustration basic_mdb_maven4.gif

    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.

    There are a number of files included in the project; see Table 9-9 for the purpose of each file.

    Table 9-9 Files Created for the Basic MDB Project

    File Purpose

    pom.xml

    The Maven Project Object Model (POM) file that describes your new project. It includes the Maven coordinates that you specified for your project, and it also includes the appropriate plug-in definitions to use the WebLogic Maven Plug-in to build your project.

    Files under src/main/java

    An example Message Driven Bean that is used by the web application to store data.

    All other files

    HTML files that make up the web application user interface.


  2. 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.

  3. Customize the POM to suit your environment. See Section 9.2.1.

  4. Compile your Basic MDB Project. See Section 9.2.2.

  5. Package your Basic MDB Project. See Section 9.2.3.

  6. Deploy your Basic MDB Project. For information about deploying it using Maven, see Section 9.2.4. For information about deploying it using other options, see Section 9.2.5.

  7. Test your Basic MDB Project.

    You can test the Basic MDB by visiting the following URL on the WebLogic Server where you deployed it:

    http://servername:7001/basicMDB/index.xhtml
    

    The user interface for the Basic MDB looks like the following:

    Description of wls_12.jpg follows
    Description of the illustration wls_12.jpg

    Provide the Account Name and Amount, then select Deposit:

    Description of wls_14.jpg follows
    Description of the illustration wls_14.jpg

    As indicated in the user interface, you must check the WebLogic Server output to find the message printed by the MDB. It looks like the following example:

    The money has been deposited to frank, the balance of the account is 500.0