Simple Embedded GlassFish App using Maven

Today's blog demonstrates how to create a very simple GFE (GlassFish Embedded) application.  The application requires no manual downloads.  GlassFish need not be installed and no GlassFish files of any kind need to be present.

The application uses a very simple web app named, appropriately, simple.war.  The simple.war file has been checked into Subversion for this project.  This breaks the usual rules of checking in only source code.  But I wanted to make this application as simple as possible for you to use.  You could replace simple.war with your own not-so-simple web app by renaming it to simple.war and overwriting the original.

Here is how to checkout and build the sample project:

  • svn co https://svn.dev.java.net/svn/glassfish-svn/branches/embedded_v3_prelude_release/embedded/samples/SimpleMaven
  • cd SimpleMaven
  • mvn

You can run the GFE application by executing r.sh(\*NIX) or r.bat(Windows).  If you are on \*NIX don't forget to make r.sh executable (chmod +x r.sh)

What Does this Sample GFE Do?

  1. Create a GFE server
  2. Create a HTTP listener at port 7777
  3. Start the GFE server
  4. Deploy simple.war to the GFE server
  5. Send a request to simple at port 7777 and print the results
  6. Wait for user to kill the server (\^C) 

Details

  • Maven downloads the GFE jar to your local repository
  • The Maven  Dependency plugin is used to copy the GFE jar from your local repository to the target directory.  Why?  So the run script will work in all scenarios -- since I don't know where your local repository lives.  It isn't strictly necessary,  you could point the classpath to the location of the file in your local repository.
  • The pom.xml for this project is as simple as possible.  The copying over of the GFE jar is the messiest part of the pom.xml.  Take a moment to examine pom.xml
  • There is one java file for this project.  Take a look at it.  Change the port from 7777 to 12345 or your favorite port number.  Have it deploy 2 or 3 more web apps.  Play around with it.

Next Steps

It would be nice if we didn't have to use the run scripts.   It would be nice to have Maven run the app.  In the next installment in this series I will show you just how to do that with the GFE plugin!







 https://svn.dev.java.net/svn/glassfish-svn/branches/embedded_v3_prelude_release/embedded/samples/SimpleMaven

Comments:

Hi! The svn repository asks for authentication, isn't it public?

tnx,
Pedro

Posted by Pedro on February 02, 2009 at 11:16 PM PST #

'guest' did the job. sorry to bother :)

Posted by Pedro on February 02, 2009 at 11:19 PM PST #

Just tried. Could not locate the glassfish repository, perhaps you should add a note?

Posted by Thorbjørn Andersen on June 15, 2010 at 04:28 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

ByronNevins

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today