MavenAndNetBeansForGlassFish

Developing Enterprise Applications for GlassFish using Maven and NetBeans

(by Wouter van Reeven)

With the release of NetBeans 6.0, Maven gets a firm intergration with NetBeans by means of a plugin that can be installed via the NetBeans Update Center. This article describes how to setup Maven-enabled Enterprise Applications in NetBeans and how to deploy them to GlassFish. Enterprise Applications are applications that contain a jar file with EJB3.0 Entities and Session Beans and a war file with a web application that makes use of the EJB jar to manage data stored in a database. Following the steps in this article, you will end up with a very simple enterprise application containing one Entity, one Session Bean, one JSF Managed Bean and one JSF page using that managed bean. This should be enough to get you started and to enable you to extend that application to your own needs.

Setting up NetBeans

To enable Maven in NetBeans, you need to install the MevenIDE plugin. Simply click Tools -> Plugins

Image:01-tools_plugins_MavenAndNetBeansForGlassFish.png

and select all 7 plugins from the Maven category in the Available Plugins tab

Image:02-select_all_maven_plugins_MavenAndNetBeansForGlassFish.png

Next hit the Install button and finish the wizard that pops up.

Defining the projects

In NetBeans, a "normal" enterprise application consists of a parent EAR project with EJB and WAR projects as child projects. A Maven-enabled enterprise application looks almost the same but there is a difference. The parent project cannot be an EAR project since any parent project HAS to be a pom project. Defining the parent project as an EAR project and putting child projects under it, generates this error

Image:03-ear_aggregate_project_generates_error_MavenAndNetBeansForGlassFish.png

The "workaround" is simple: just create a parent pom project and then create ear, ejb and war child projects.

Creating the Parent POM Project

To create the parent pom project, select File -> New Project and select Maven in the list to the left of the frame that pops up. Select Maven Project to the right and click the Next button.

Image:04-creating_a_maven_project_MavenAndNetBeansForGlassFish.png

In the next frame, select the "Maven Quickstart Archetype" archetype and click the Next button.

Image:05-selecting_a_maven_archetype_MavenAndNetBeansForGlassFish.png

In the third frame specify the Project Name, Project Location, Group Id, Version and Package. For now, the version and package don’t matter much. But it’s nice to have some meaningful name like "MavenEnterpriseApplication" and a meaningful Group Id like "nl.amis.maven.enterprise".

Image:06-specifying_the_maven_properties_MavenAndNetBeansForGlassFish.png

Now we’ll have to edit the pom.xml file by hand to make it suit our needs. Some of the properties can be edited by right clicking the project name and selecting properties. These properties can also directly be edited by opening the pom.xml file and modifying the XML. Using the built in editor saves us a lot of typing, so right click the MavenEnterpriseApplication project name and select Properties. Since this is our parent project that we’ll only use for general Maven configuration purposes, we need to change the packaging from jar to pom.

Image:07-using_the_maven_properties_editor_MavenAndNetBeansForGlassFish.png

Next, select the Source category and set the Source/Binary format to 1.5. Click OK to exit the editor and save the changes you made. Most of the other changes we need can be made without actually editing the pom.xml file. First of all, by default Maven creates one source class and one test class in every project that is created. We won’t need those in this project. Go to the Files window right of the Projects window (if it’s not visible select the Windows menu item and then Files) and expand the project. Select the src directory and hit the Delete button. Next return to the Projects window. By default Maven also generates a JUnit dependency and we won’t need that either. so expand the Test Libraries node, right click the junit-3.8.1.jar library and select Remove Dependency. That’s it for now.

The EJB Project

Next we’ll create the EJB Project. To do so, follow the same three steps as when creating the new Parent POM Project. This time make sure the Project Location is the root directory of the Parent POM Project. This will make Maven recognise it as a sub-module managing the necessary changes to the pom.xml files of both the parent and the sub-module. I chose these settings for the EJB module:

Project Name: MavenEnterpriseApplication-ejb
Project Location: /home/wouter/NetBeansProjects/MavenEnterpriseApplication
Group Id: nl.amis.maven.enterprise
Package: nl.amis.maven.enterprise

The package I specified is the same as the package I specified for the Parent POM Project. Note that the Parent POM Project pom.xml file was modified to now include a reference to the EJB module:

  <modules>
    <module>MavenEnterpriseApplication-ejb</module>
  </modules>

The EJB module pom.xml file was created with a reference to the Parent POM Project:

  <parent>
    <artifactId>MavenEnterpriseApplication</artifactId>
    <groupId>nl.amis.maven.enterprise</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>

Right click the MavenEnterpriseApplication-ejb project and select Properties. This time change the packaging to "ejb". After clicking OK to save the changes and reopening the Properties editor it is also possible to open the Run Category and select the GlassFish V2 application server. You don't have to do this, since we will use the EAR project that we will create later to deploy to GlassFish. Moreover, specifying GlassFish as the target server will not enable selecting data sources from GlassFish for the persistence unit we are about to create. Please note that this may change in future versions of the MevenIDE plugin.

Finally, you need to tell Maven to make use of the version 3.0 EJB Maven plugin. This can be done by adding these lines to the pom.xml file by hand

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId>
                <configuration>
                    <ejbVersion>3.0</ejbVersion>
                </configuration>
            </plugin>
        </plugins>
    </build>

Let’s create our Entities and Session Beans now. We will need to use a NetBeans local database connection to generate the beans. Later on, before deploying our project, we will need to make adjustments to the Persistence Unit persistence.xml file so our deployed application makes use of the datasource we defined in Glassfish. But first things first.

Creating the beans

If you haven’t created a database connection in NetBeans yet, this would be a good time to do it. If you don’t NetBeans will prompt you for it later. However, for most databases you need to register your JDBC driver first and you won’t be able to do it when NetBeans prompts you for a database connection. After having created the database connection, right click the MavenEnterpriseApplication-ejb project and select New -> Entity Classes From Database. In the wizard that pops up, select your database connection and then select the tables you want to create Entities for. Since I am using Oracle XE I have created a database connection to the HR schema. Therefore I selected all tables in the HR schema.

Image:08-selecting_all_tables_in_the_hr_schema_MavenAndNetBeansForGlassFish.png

After clicking next you get the chance to rename the Entity classes to your liking and specify the package in which they will be created. More importantly, here is where you can create a Persistence Unit. Click the "Create Persistence Unit" button and give the Unit a more sensible name, e.g. "MavenEnterpriseApplication-ejbPU". Finish creating the Persistence Unit and Entities.

To make sure that our application uses the Glassfish data source, the persistence.xml file needs to be modified. Expand the Other Sources -> Resources -> META-INF nodes and double click the persistence.xml file to edit it. Click the XML button to the upper left of the central edit pane and modify the XML like this

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 
             xmlns="http://java.sun.com/xml/ns/persistence" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="MavenEnterpriseApplication-ejbPU" transaction-type="JTA">
        <jta-data-source>jdbc/hr</jta-data-source>
        <properties/>
    </persistence-unit>
</persistence>

This of course assumes you have setup a JDBC connection Pool and that you have setup a JDBC Resource called 'jdbc/hr' that uses that pool in GlassFish. If you haven't done that, please make sure you have before you try and deploy your application to GlassFish, else deployment will fail!

Besides the new Entity classes and Persistence Unit, some changes have been made to the pom.xml file as well. Since the Entity classes make use of the Toplink Essentials classes, the dependencies on the toplink jars have been resolved for us. This has been done in two ways. First of all, a reference to the java.net Maven Repository has been added. Second, the depenency entries for toplink-essentials and toplink-essentials-agent have been added to the pom.xml file. Since our web project will need access to the java.net repository as well, it is wise to move the repository reference from the EJB pom.xml to the Parent POM pom.xml file. Besides that, we need to tell Maven not to include the jar files for Toplink Essentials in the EJB jar file. You need to do this by adding this line to each dependency in the pom.xml file

            <scope>provided</scope>

Since the app I am creating for this article only is a simple one, I am only going to modify one Entity class to contain an additional NamedQuery. In the Employees Entity I am adding this NamedQuery which returns a list of all available Employees

@NamedQuery(name = "Employees.getAll", query = "SELECT e FROM Employees e")

Next create a Local Session Bean by right clicking the MavenEnterpriseApplication-ejb project and selecting New -> Session Bean. Provide a name for your session bean, e.g. Data, and a package, e.g. nl.amis.maven.enterprise.ejb.session. Leave the defaults (Stateless and Local) be. Clicking the Finish button will generate an error in NetBeans. The new session bean will have the @Local and @Stateless annotations and Maven is unable to resolve them. In my case the session bean wizard even doesn’t close so I closed it by clicking the Cancel button. Fortunately this doesn’t remove the session bean!

The problem is that the two annotations are provided by the ejb-api.jar file which Maven doesn’t know of. So we need to add a dependency to that jar file by adding these lines to the EJB pom.xml file

        <dependency>
            <groupId>javax.ejb</groupId>
            <artifactId>ejb-api</artifactId>
            <version>3.0</version>
            <scope>provided</scope>
        </dependency>

Next add this mehtod definition to the DataLocal interface:

    public int countEmployees();

and this EntityManager injection and method implementation to the DataBean class

    @PersistenceContext EntityManager em;
    
    public int countEmployees() {
        return em.createNamedQuery("Employees.getAll").getResultList().size();
    }

That completes the EJB project for now!

The WAR Project

For this article, we will a simple JSF managed bean which uses the DataLocal bean to feed a JSF page that displays the number of Employees in your browser. First, create a new Project. This time, don’t create a Maven Quickstart Archetype project, but a Maven Webapp Archetype. I used these settings for it

Project Name: MavenEnterpriseApplication-war
Project Location: /home/wouter/NetBeansProjects/MavenEnterpriseApplication
Group Id: nl.amis.maven.enterprise
Package: nl.amis.maven.enterprise

Inspect the project properties and make sure this time the packaging is set to war. In order to get a proper WAR file a few modifications need to be made to the pom.xml file. First of all, these lines need to be added inside the <build> tag

        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>

This will make sure a Class-Path line will be added to the MANIFEST.MF file. Next we need to add dependencies for our EJB project, the ejb-api.jar, the jsf-api.jar, jsf-impl.jar and the servlet-api.jar by adding these lines to the pom.xml file in the same section as the junit dependency

        <dependency>
            <groupId>nl.amis.maven.enterprise</groupId>
            <artifactId>MavenEnterpriseApplication-ejb</artifactId>
            <version>1.0-SNAPSHOT</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>javax.ejb</groupId>
            <artifactId>ejb-api</artifactId>
            <version>3.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>1.2_07</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>1.2_07</version>
            <scope>provided</scope>
        </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>

The <optional> tag in the MavenEnterpriseApplication-ejb dependency will make sure that the Class-Path line in the MANIFEST.MF file will contain the MavenEnterpriseApplication-ejb.jar file which is needed for the Enterprise Containier of GlassFish to inject the DataLocal instance in the servlet that we are about to create. Before we can do that, however, we first need to resolve some conflicts that we have introduced. Maven is not able to resolve the MavenEnterpriseApplication-ejb dependency since we haven’t built any code yet. Everything will work fine once we build the Parent POM Project, but for now NetBeans cannot resolve the classes in the MavenEnterpriseApplication-ejb project when we use them in the WAR Project. So, right click the MavenEnterpriseApplication project and select build. This may take a while since Maven will probably need to download quite a buch of jar files.

Besides modifying the pom.xml file, the web.xml file that was created also needs to be modified. Maven creates a web.xml file that GlassFish won’t like. The first three lines of the web.xml file (that are the lines up to and including the line with the <web-app> tag) need to be replaced by these lines

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 

Since we would like to display our data via a JSF page, we need a faces-config.xml file. Expand the Web Pages node and then the WEB-INF node. Next right click the WEB-INF node and select New -> XML Document. If XML Document cannot be selected from the list, select Other and then search for XML document under the XML node. Name the new file "faces-config" (without the quotes, but also without the .xml extension) and finish the wizard. Replace the entire contents of the file with this

<faces-config version="1.2" 
              xmlns="http://java.sun.com/xml/ns/javaee" 
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
    <application>
    </application>
</faces-config>

Next some modifications need to be made to web.xml for JSF to operate correctly. I suggest you now add these lines to web.xml

    <!-- Use Documents Saved as *.jsp -->
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.jsp</param-value>
    </context-param>
    
    <!-- Faces Servlet -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    
    <!-- Faces Servlet Mapping -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

Basically, these lines specify that our JSF pages should have the .jsp suffix, and which URL pattern should be caught by that Faces servlet. In short, browsing to, say, http://localhost:8280/MavenEnterpriseApplication-war/index.jsf will make the Faces servlet process index.jsp and render its output.

Add a backing bean

Before we add a JSF page we need a backing bean to fetch data from our local session bean. This bean will fetch the number of Employees in our company from the local session bean and provide a getter for our future JSF page. A very dull application, but it suffices for the purpose of this article. This bean simply could look like this

package nl.amis.maven.jsf.beans;

import javax.ejb.EJB;
import nl.amis.maven.enterprise.ejb.session.DataLocal;

public class NumberBackingBean {

    private int numberOfEmployees;
    
    @EJB DataLocal dataLocal;
    
    public int getNumberOfEmployees() {
        return dataLocal.countEmployees();
    }
    
    public void setNumberOfEmployees(int numberOfEmployees) {
        this.numberOfEmployees = numberOfEmployees;
    }
    
}

These lines in faces-config.xml will register the bean in the JSF context

    <managed-bean>
        <managed-bean-name>NumberBackingBean</managed-bean-name>
        <managed-bean-class>nl.amis.maven.jsf.beans.NumberBackingBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

These lines tell JSF to initiate and make available an instance of nl.amis.maven.jsf.beans.NumberBackingBean under the name NumberBackingBean.

Add a JSF page

JSF pages can be very simple, or very complex. In this case, we will create a simple JSF page. The idea is to invoke the getNumberOfEmployees method in our NumberBackingBean bean and display the return value in a browser. Simply open the index.jsp file and replace the contents of the file with

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body>
    <f:view>
        <h:outputText value="The number of Employees is #{NumberBackingBean.numberOfEmployees}"/>
    </f:view>
    
</body>
</html>

The EAR Project

The final project we need is the one that will create the ear file using the MavenEnterpriseApplication-ejb and MavenEnterpriseApplication-war projects. First create a new Maven Quickstart Archetype project. I used these settings:

Project Name: MavenEnterpriseApplication-ear
Project Location: /home/wouter/NetBeansProjects/MavenEnterpriseApplication
Group Id: nl.amis.maven.enterprise
Package: nl.amis.maven.enterprise

Modify the project properties and set the Packaging to ear. Remove src directory by going to the Files window and deleting the src directory. Remove the junit Test Library from the Projects window. Finally, add the dependencies on the MavenEnterpriseApplication-ejb and MavenEnterpriseApplication-war projects like this

        <dependency>
            <groupId>nl.amis.maven.enterprise</groupId>
            <artifactId>MavenEnterpriseApplication-ejb</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>ejb</type>
        </dependency>
        <dependency>
            <groupId>nl.amis.maven.enterprise</groupId>
            <artifactId>MavenEnterpriseApplication-war</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>

Building the Parent POM Project should now be succesfull:

------------------------------------------------------------------------
Reactor Summary:
------------------------------------------------------------------------
MavenEnterpriseApplication ............................ SUCCESS [2.953s]
MavenEnterpriseApplication-ejb ........................ SUCCESS [4.004s]
MavenEnterpriseApplication-war ........................ SUCCESS [1.612s]
MavenEnterpriseApplication-ear ........................ SUCCESS [0.764s]
------------------------------------------------------------------------
------------------------------------------------------------------------
BUILD SUCCESSFUL
------------------------------------------------------------------------
Total time: 9 seconds
Finished at: Tue Dec 18 11:20:24 CET 2007
Final Memory: 49M/94M
------------------------------------------------------------------------

Deploying to GlassFish

There are a few ways of deploying applications to GlassFish. NetBeans by default uses the Java EE Application Deployment API to deploy to GlassFish. I'd like to opt for using the GlassFish command line utilities to deploy to GlassFish for now. The advantage is, that you don't need to extend Maven to be able to use this. Another way of deploying might be cargo but I am not sure it is working right now with GlassFish.

The GlassFish command line utility to deploy to both local and remote servers is asadmin. The general command that needs to be issued is

asadmin deploy --user=<adminuser> <path to jar/war/ear>

In this command, <adminuser> is the username of a user with admin rights. By default this is "admin". And <path to jar/war/ear> refers to the path to the archive containing the application that you would like to deploy. This path could be something like "C:\devel\MyProject\MyProject-ear\target\MyProject-1.0-ear.ear" or "./MyProject-ear/target/MyProject-1.0-ear.ear". the latter path, of course, is a path relative to the current working directory.

The above command assumes you are deploying to a locally installed and running GlassFish server. Things get a little more complicated when deploying to a remote server. The simplest way of doing such a deployment is

asadmin deploy --user=<adminuser> --host=<hostname> <path to jar/war/ear>

In this command, the arguments <adminuser> and <path to jar/war/ear. have the same meaning as in the first command. And <hostname> of course refers to the host to which the application should be deployed. Valid hostnames are localhost, appserv1, appserv1.my.domain but also the 192.168.0.123 IP address. The first and second commands assume your admin console is listening on port 4848. In case the admin console is listening on a different port you can add this flag

--port=<port>

By default, the password of the local GlassFish server is stored in a file called .asadminpass in the home directory of the user that installed the GlassFish server. On Linux the home directory usually is /home/<username> or sometimes export/home/<username>. On Windows the default location of this file is C:\Documents and Settings\<username> (as far as I know. I have modified my default home due to cygwin) but there are many ways for system administrators to modify this location.

By default, the asadmin utility will look into the .asadminpass file for the password to use when deploying your application. This password, however, is host dependent. My .asadminpass file only contains the password for the admin user on my local GlassFish installation. Therefore, deploying to a remote host will make asadmin prompt for the admin password:

$ ./java/nb60b2/glassfish-v2-b58g/bin/asadmin deploy --user=admin --host=laptop --port=4848 \
./MavenEnterpriseApplication-ear/target/MavenEnterpriseApplication-ear-1.0-SNAPSHOT.ear 
Please enter the admin password>

Fortunately, the asadmin utility allows you to provide the admin password through the –passwordfile command line flag. The argument to this flag is the path to the file containing the admin password, e.g.

--passwordfile="C:\Documents and Settings\wouter\remote_admin_password.txt"

The password file should contain a line like this

AS_ADMIN_PASSWORD=adminadmin

Now the asadmin command completes without prompting for the password:

$ ./java/nb60/glassfish-v2/bin/asadmin deploy --user=admin --passwordfile=/home/wouter/.asadminpassword --host=laptop --port=4848
./MavenEnterpriseApplication-ear/target/MavenEnterpriseApplication-ear-1.0-SNAPSHOT.ear
Command deploy executed successfully.

Moving to Maven

Since it is my purpose to use Maven for the deployment of my applications, I need a way to execute the asadmin command from Maven. By default Maven doesn’t allow for executing system commands. Fortunately the Mojo people at codehaus.org (which also hosts the MevenIDE plugin) have developed a plugin to execute system commands. The use of this plugin is fairly simple. the plugin needs to be registered in the pom.xml file of the project that needs the plugin and then the plugin needs to be configured in such a way that it will execute the system command. Here’s the pom.xml part that works for me. I have put this in the pom.xml file of the EAR project.

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>/home/wouter/java/nb60/glassfish-v2/bin/asadmin</executable>
                    <arguments>
                        <argument>deploy</argument>
                        <argument>--user=admin</argument>
                        <argument>--passwordfile=/home/wouter/.asadminpassword</argument>
                        <argument>--host=localhost</argument>
                        <argument>--port=4848</argument>
                        <argument>target/${artifactId}-${version}.${packaging}</argument>
                    </arguments>
                </configuration>
            </plugin>
        </plugins>
    </build>

Let’s focus on the configuration part. The executable tag contains the full path to the asadmin utility. I have tried to use the workingdirectory and basedirectory tags that are mentioned on the plugin page but for some reason they didn’t do what I expected them to do. So I just put the complete path there and that works just fine.

There are two ways to add command line arguments to the asadmin utility and they result in the same behaviour. One way is to specify a commandlineArgs tag and put the entire rest of the command line in that tag. The other way is to make use of the arguments tag with nested argument tags as in the example above. Basically all command line arguments that I explained in the first part of this article are there. simply replace all parts behind the "=" symbols with your values and you should be fine.

The last argument makes use of the parameter inheritance of Maven. Maven will expand the parameters to the values that are set by Maven. In this case, the line

${artifactId}-${version}.${packaging} 

will expand to

MavenEnterpriseApplication-ear-1.0-SNAPSHOT.ear

Pretty neat huh? Please be aware that that final argument only works when it is invoked from the EAR project. If you’d like to run the exec target from e.g. the Parent POM Project you’ll have to modify the path so Maven can find the ear file that needs to be deployed.

In order to do the actual deployment, the exec:exec goal needs to be executed. From within NetBeans this can be done by right clicking the EAR project and selecting custom -> Goals. A window pops up in which you can specify the goal that needs to be performed. The cool thing is that MevenIDE is smart enough to auto complete whatever you type, so entering "ex" should give you the choice between exec:exec and exec:java. In this case choose the exec:exec goal. Tick the Show Debug Output check box to get extended debugging info. This is particularly useful in case the exec:exec goal fails.

Image:09-selecting_a_maven_goal_MavenAndNetBeansForGlassFish.png

If all goes well, Maven should report that the deployment was successful

Scanning for projects...
Searching repository for plugin with prefix: 'exec'.
artifact org.codehaus.mojo:exec-maven-plugin: checking for updates from NetBeansIDE-repo-internal
----------------------------------------------------------------------------
Building MavenEnterpriseApplication-ear
   task-segment: [Exec:exec]
----------------------------------------------------------------------------
project-execute
[Exec:exec]
Command deploy executed successfully.
------------------------------------------------------------------------
BUILD SUCCESSFUL
------------------------------------------------------------------------
Total time: 3 seconds
Finished at: Tue Dec 18 11:47:50 CET 2007
Final Memory: 45M/103M
------------------------------------------------------------------------

So, if you now brose to http://localhost:8080//MavenEnterpriseApplication-war/index.jsf (or whatever host you deployed your app to and on whatever port GlassFish on that host is listening to) you should see

Image:10-the_final_result_MavenAndNetBeansForGlassFish.png

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo