GlassFish v3 Demo at Sun Tech Days
By user12611203 on Sep 21, 2007
The Sun Tech Days Boston event was held last week. As part of Sun Tech Day on Wednesday, Tom Kincaid gave a talk on Java EE 6 and the future of the EE platform. This blog captures the demonstration that we gave of an early preview of GlassFish v3 (which is implementing Java EE 6). For more information on Sun Tech Days Boston, Ryan Shoemaker has recorded his days at the conference: part 1, part 2.
In the demonstration, we wanted to show four main features of GFv3:
- The modular nature of GFv3, which results in very fast startup time.
- Containers for web apps and JRuby apps loading on demand.
- Simplified deployment of JRuby applications.
- The inclusion of Java code inside a Ruby application.
GlassFish v3: The "preview1-b2" build is available
Installation is simple: just
java -jar <filename>. Drop the
bin directory into your path and you're all set.
NetBeans and the GFv3 plugin: By now, the Beta 1 version of
is out. Since it hadn't been released at the time of the conference,
I went with a daily build from September 7th and grabbed the GlassFish v3
plugin from the beta update center. When you add GF to the NetBeans's server list,
NB gives you a download button to grab the app server:
The version isn't the same as the preview 1 b2 shapshot that I was using, but that combination worked anyway. You don't need to add the GFv3 server to NetBeans for these examples since I give instructions for deploying/undeploying from the command line.
JRuby: Following the directions on
you can install JRuby 1.0, add the
bin directory to your path, and install Rails with
jruby -S gem install rails -y --no-rdoc
After this, just add the
JRUBY_HOME value to the end of the
asenv.\* file in glassfish/config/.
Running GlassFish v3: In your glassfish/lib directory, you can see all of
the jars that make up the kernel and containers of GFv3. That little (less than 15k)
jar file called glassfish-10.0-SNAPSHOT.jar is your target. Assuming you are
in the glassfish directory, give the Java command:
java -jar lib\\glassfish-10.0-SNAPSHOT.jar
...and you should see something like this:
D:\\glassfish>java -jar lib\\glassfish-10.0-SNAPSHOT.jar [#|2007-09-14T16:32:02.589-0400|INFO|GlassFish10.0|javax.enterprise.system.core|_ThreadID= 10;_ThreadName=Thread-2;|Listening on port 8080|#] [#|2007-09-14T16:32:02.770-0400|INFO|GlassFish10.0|javax.enterprise.system.core|_ThreadID= 10;_ThreadName=Thread-2;|Supported containers : phobos,web,php,jruby|#] [#|2007-09-14T16:32:02.790-0400|INFO|GlassFish10.0|javax.enterprise.system.core|_ThreadID= 10;_ThreadName=Thread-2;|Glassfish v3 started in 791 ms|#]Note the startup time, in this case under .8 seconds on a slightly old laptop. You can browse http://localhost:8080 to see that the server has indeed started and is serving static html content. Add another html file to
domains/domain1/docrootand you can view it in the browser, or edit
index.html(go ahead, it's your app server!) to see changes. Now it's time to add some applications.
A web application example: In NetBeans, create a simple web application.
Ctrl-Shift-n is one way to bring up the "New Project" window, and you can
choose Web -> Web Application to create a simple web app. The
index.jsp file will come up automatically in the editor. Just add some text
of your choosing and build with F11. We called the project "jsphello" and the
war file was built in jsphello/dist/jsphello.war. If you have the GFv3 plugin,
you can deploy with NetBeans, but we deployed from the command line in order to watch
both the server and asadmin output at the same time. To deploy, use
asadmin deploy --path
<path to jsphello.war>
The asadmin script will call a Java command to deploy the application, and your output should look something like:
D:\\examples>asadmin deploy --path jsphello\\dist\\jsphello.war D:\\examples>java -jar D:\\glassfish\\bin\\\\..\\lib\\admin-cli-10.0-SNAPSHOT.jar deploy --path jsphello\\dist\\jsphello.war SUCCESS : Application jsphello deployed successfully
Note that in the GlassFish server log, the web container is loaded when it is needed.
If you stop and restart the server now, you will that the web container is loaded at
startup since a web application has been deployed. You can undeploy the application
asadmin undeploy --name jsphello
To get a list of deployed applications, use:
After undeploying the web application and using the "list-applications" command, your output will look like the text below. You can see that the web container is loaded, ready for another web application to be deployed (if you restart the server, it will not load the web container until you need it).
D:\\examples>asadmin list-applications D:\\examples>java -jar D:\\glassfish\\bin\\\\..\\lib\\admin-cli-10.0-SNAPSHOT.jar list-applications SUCCESS : List of deployed applications per container ContractProvider : web_ContractProvider properties=(Connector module=com.sun.enterprise.glassfish:gf-web-connector, Sniffer module=class com.sun.enterprise.v3.web.WebSniffer)
A JRuby example: In NetBeans, open the New Project window and choose
Ruby -> Ruby on Rails Application. On the next page, give the application
a name (e.g., "railshello") and click Finish. After the IDE is finished generating
the files needed, you can add a controller and view for a simple "Hello World" application.
Right-click on the project name and choose Generate. Fill out the resulting dialog
as below and click Ok:
NetBeans will then generate say_controller.rb and hello.rhtml files for you. We edited the controller to add a string and then used that string in the "hello" view.
class SayController < ApplicationController def hello @hello_string = "Hello World" end endhello.rhtml:
<h1>Say#hello</h1> <p>Find me in app/views/say/hello.rhtml</p> <%= @hello_string %>
GlassFish v3 supports a "straight" deployment of JRuby code. To deploy our 'railshello' application, we don't have to first wrap it in a war file. We can simply call asadmin and deploy the application directory (asadmin calls the proper "java -jar ..." command):
D:\\examples>asadmin deploy --path railshello D:\\examples>java -jar d:\\glassfish\\bin\\\\..\\lib\\admin-cli-10.0-SNAPSHOT.jar deploy --path railshello SUCCESS : Application railshello deployed successfully
Watching the server log, you can see that the JRuby/Rails runtime is loaded into GFv3
as needed. Then the application is deployed and is ready to run.
To access the page once it's deployed, use http://localhost:8080/railshello/say/hello.
This directory deployment of the application makes for a very fast development
cycle. For instance, if you change the
@hello_string value in say_controller.rb,
you only have to save the file and reload the page in your browser.
Adding some Java into the Ruby code: Using the same JRuby/Rails application, you
can add Java code directly into the say_controller.rb file without any other compilation
or deployment steps. For our example, we added some trivial Java code in to create a
HashMap and set the value of
@hello_string using a value in this map. The
new version of say_controller.rb:
require 'java' include_class 'java.util.HashMap' class SayController < ApplicationController def hello myMap = HashMap.new myMap.put("key", "Hello from Java code!") @hello_string = myMap.get("key") end end
Now simply save the file and reload the page in your browser. The mix of Java and
JRuby code works without any other steps since we have done the directory deployment.
Finally, to undeploy the application, give the same command that you used to undeploy
the jsphello example:
asadmin undeploy --name railshello
Though this early version of GFv3 does not show anything in the log when you undeploy the app, you can verify that it is no longer deployed with the asadmin 'list-applications' command described above.