Posts Tagged ‘eclipse’

Glassfish 4.0 : “Hello world” application with Maven 3

The following steps will allow you to develop and deploy a first demo web-app with Glassfish Server 4.
1) To install Glassfish 4.0 follow the steps at
For example, you can get the zip version and extract into: C:\glassfish4.

2) If you´re working on a Windows Desktop Rename glassfish4/glassfish/bin asadmin to *.s to prevent the following Maven error:
Unable to start domain "domain1". IOException: Cannot run program"C:\glassfishv3\glassfish\bin\asadmin": CreateProcess error=193, %1 is not a valid Win32-Application

In this way The system will run asadmin.bat, instead of calling the Linux script (provided with no file extension by Glassfish).

3) On Eclipse install Glassfish plugin ( to manage the server graphically. Otherwise you would not be able to installing with the command File>New>Other>Server> etc.
Starting Glassfish for the first time, you will have a user called “admin” with no password. You can manage Glassfish with Admin-Console available at: http://localhost:4848/ or even with asadmin CLI console (under C:\glassfish4\glassfish\bin).

4) To deploy your application using Maven, create the settings.xml file under the .m2 folder (for example, under Windows at the location: C:\Users\username\.m2), providing the glassfish profile credentials: they will automatically imported in the pom.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="" 

5) Create a new Maven project with the maven archetype “maven-archetype-webapp” template. As a default you can already find the index.jsp HelloWorld page.

6) Add the following plugins to the pom.xml:


					<!-- <webXml>src\main\webapp\WEB-INF\web.xml</webXml> -->



7) Launch the maven command:
clean package glassfish:deploy

You may find errors related to the Dynamic Web Module in the Eclipse project, even if the maven gives you “BUILD SUCCESS”. For now it´s ok.

With the given pom.xml the application will be deployed into:

You can see it up and running at: http://localhost:8080/Glassfish_HelloWorld/

You can manage the applications, for example editing the Content Root folder, directly in the administration console.

Demo Code available at:

Generating JAXB classes from a xsd schema in a Maven project

If you want to geenrate JAXB classes from a xsd schema in a Maven project, you need to specify the dependencies for jaxb and the plugin.

The pom.xml file is like the following:

<project xmlns="" xmlns:xsi=""

        <!-- JAXB xjc plugin that invokes the xjc compiler to compile XML schema into Java classes.-->
                <!-- The schema directory or xsd files. -->
                <!-- The package in which the source files will be generated. -->
                <!-- The working directory to create the generated java source files. -->

in the configuration tags you need to specify “schemaDirectory” (the location of the .xsd file) and in the “outputDirectory” the destination folder for the generated classes.

First of all you need to run the maven compile command. Then you can generate the JAXB classes: in eclipse, for example, you can right-click on the project and run New>Other>JAXB>”JAXB Classes from a Schema”.
Of course you need to add the Eclipse plugin first.

Eclipse won´t generate automatically the @XmlRootElement annotation. You will have to add it on your own, like this:

@XmlType(name = "MBean", propOrder = {
public class MBean {