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
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?
- Create a GFE server
- Create a HTTP listener at port 7777
- Start the GFE server
- Deploy simple.war to the GFE server
- Send a request to simple at port 7777 and print the results
- Wait for user to kill the server (\^C)
- 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.
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!