GlassFish Embedded API


Published on

An overview of the GlassFish Embedded API

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

GlassFish Embedded API

  1. 1. Embedded GlassFish Byron Nevins, November 6, 2008
  2. 2. History ● If embedded is so useful – why didn't we offer it in 7, 8, or 9? ● The Launcher was really an integral/ensnarled part of the AppServer. Launcher figured out runtime properties in domain.xml and other config files and then passed this info to the server JVM. ● That has changed. Now the launcher is responsible mainly for setting JVM startup options. GF itself figures out its own configuration. ● As a result the AppServer can be started from any JVM
  3. 3. Highlights ● Who? Development: Kohsuke Kawaguchi, Byron Nevins Management: Nazrul Islam ● When? November 6, 2008 ● What? Embedded GlassFish Initial Rollout ● Where?
  4. 4. Why? ✔ Very fast startup ✔ No GF installation needed. ✔ Able to run inside of a Maven JVM ✔ Support deployment and running of Web Applications ✔ Allow easy HTTP port setting
  5. 5. How? Embedded means that a very special type of GlassFish is run. ● No fancy class loading frameworks are used. ● No GF installation is needed or used ● No persistent Domain is needed or used
  6. 6. Use Cases ● Ability to run a web application like a regular java application ● Unit Tests. A servlet can define unit tests that will automatically start an embedded GF, deploy the servlet, run and test the servlet and then shutdown GF. ● Fast Jetty-like development ● Use as a tiny web container. E.g. Hudson ● Large complex testing frameworks do not require a separate AppServer domain to be configured and run.
  7. 7. Examples - API A simple Maven project that uses Embedded GlassFish This is needed inside pom.xml of your project: <dependencies> <dependency> <groupId>org.glassfish.embedded</groupId> <artifactId>glassfish-embedded-all</artifactId> <version>3.0-Prelude-SNAPSHOT</version> </dependency> </dependencies> That's all you need in order to use Embedded GlassFish in your code!
  8. 8. Examples - API A simple Maven project that uses Embedded GlassFish Now create a main Java class and add this (no error checking for clarity): import org.glassfish.embed.*; public static void Main(String[] myWarFiles) { try { Server myGF = new Server(9999); for(String fname : myWarFiles) myGF.deploy(new File(fname)); myGF.start(); // do stuff here! myGF.stop(); } catch(Exception e) { System.out.println(quot;Got an Exception: quot; + e); } } The Web Applications will be available and listening for HTTP traffic at port 9999 (remove the stop() call of course!) You can look at an actual smoketest that we use that does exactly this: Ref:
  9. 9. Examples - API A non-Maven project that uses Embedded GlassFish In this case you need to get the all-in-one Embedded jar here: Nightly: Promoted: Let's say you download the latest nightly which is named “latest.jar” You write code exactly as in the previous slide except you need to add latest.jar to the classpath of your Java compiler. You run your code simply by adding latest.jar to the classpath. Here is a simple example Windows script: setlocal set CP=myEmbeddedApp.jar;latest.jar set DEBUG=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1322 java %DEBUG% -cp quot;%CP%quot; com.yourCompany.Main %* endlocal
  10. 10. Examples - API-Helper You can go one level higher than the Embedded GlassFish API. We have a few helper classes that make it even simpler. Sample Code ScatteredWar swar = new ScatteredWar(.....); EmbeddedInfo info = new EmbeddedInfo(); info.addScatteredWar(swar); info.addArchive(new File(“myOtherApp.war”); info.setHttpPort(12345); EmbeddedRunner runner = new EmbeddedRunner(info);;
  11. 11. Examples – No Java Would you like to try Embedded GlassFish but you don't want to write any Java code? No Problem! Say you have downloaded the Embedded GlassFish jar file as “latest.jar” java -jar latest.jar -p 3456 myapp1.war myapp2.war This will start Embedded GlassFish listening at port 3456 with the 2 applications deployed. Java -jar latest.jar –help (or no argument at all) will show helpful information.
  12. 12. Schedule Immediate: JDBC/JavaDB support has just been added. An API for configuring JDBC will be in place this week. Support for supplying your own configuration in domain.xml will be added this week. November 14, 2008 Support for ● Servlet 2.5 ● JSP 2.1 ● JSF 1.2 ● JSTL 1.1 ● JPA ● JDBC 4.0
  13. 13. References ● The Embedded GlassFish project: ● Schedule: ● Source Code: ● Arun Gupta's Blog on Embedded ● API JAVADOC: ● Build Instructions: ● Issue Tracker: ● Mailing Lists: ● Promoted Builds: ● Nightly Builds: