Thursday Dec 03, 2009

TOTD #115: GlassFish in Eclipse - Integrated Bundle, Install Stand-alone or Update Existing plugin

There are three options for Eclipse users interested in exploring GlassFish. They can either use an integrated bundle, install the GlassFish plug-in in an existing Eclipse version, or update an older GlassFish plugin in a stand-alone Eclipse to the latest version. These options are explained below.

GlassFish Tools Bundle for Eclipse 1.1 is an integrated bundle based on Eclipse 3.4.2 and includes GlassFish v2 and v3 Prelude pre-registered and configured and optionally JDK 1.6 U12. The work towards version 1.2 can be tracked by following the 1.1.x releases (1.1.7 is the latest). This new version is based on Eclipse 3.5.1, includes GlassFish v3 build 74 pre-registered and configured, several plugins (JSF Facelets, JAX-WS, Maven m2) and several Java EE 6 wizards to provide a seamless development and deployment experience with Java EE 6 & GlassFish v3. There are several other niceties in the newer release like pre-registered MySQL JDBC driver, updated Java EE 5 and Java EE 6 javadoc and code completion.

However what to do if you are already using an Eclipse version in your environment ?

The basic requirement is Eclipse 3.4+. A GlassFish plugin can be easily installed in any Eclipse 3.4+ and provides all the GlassFish-related functionality. The screencast #28 shows how to get started with Eclipse 3.4.2 and configure GlassFish as a standard server adapter.

If you are using Eclipse 3.5.0, then the standard technique described in the above screencast will not work because of the issue #280365. Fortunately, the bug report also has a workaround. Instead of using the "Download additional server adapter", install using the "Help", "Install New Software ..." and explicitly adding the GlassFish plugins update site. A screen snapshot looks like:

If you are using Eclipse 3.5.1, then the standard technique of "Download additional server adapter" works as described in the screencast #28. A screen snapshot looks like:

If you already have an existing version of GlassFish plugin installed, then it can be updated as described in TOTD #66. The process is much more simplified now and menu items have changed little bit in Eclipse 3.5.x - "Check for Updates" instead of "Software Updates ...". The screen snapshot looks like:

Now you can start developing your applications using Eclipse. Several blog entries have already been published:

  • TOTD #102 explains how to use Servlet 3.0 and EJB 3.1 wizards in Eclipse.
  • TOTD #99 explains how to create a JPA 2.0 compliant application.
  • TOTD #98 explains how to create a Metro JAX-WS Web service.
  • TOTD #54 shows how to create a JavaServer Faces application with Eclipse.

Future blogs will provide more details on the new features added recently. Until then, the GlassFish Plugin Release Notes provide a summary.

On a slightly different note, you can even run GlassFish with Eclipse Equinox OSGi runtime as explained in TOTD #103.

Technorati: totd eclipse glassfish v3 javaee

Monday Oct 12, 2009

Oracle Open World 2009 - Day 2 Report

Following from Day 1, the Day 2 started with Charles Phillips and Safra Catz keynote. The keynotes at Open World are significantly different from JavaOne or any other developer conference I've attended so far. Of course they are expected to be because Open World is not primarily a developer's conference. Oracle Develop (OD) certainly closely mimic any of the conferences I've typically attended. My "exhibitor" badge restricted me from attending any of the sessions at OD though :-(

Here are some interesting statistics about the conference:

5 content streams (Database, Applications, Industries, Management & Infrastructure, & Middleware)
314 demo kisosk
401 partners & customer exchibiting
1966 educational sessions (10% more than last year)
4500 Oracle developers/experts for you
81,266 hotel room nights
170,000 cups of coffee
182,000 online participation

Here are some interesting sightings from the Open World exhibitor pavilion:

  • Tata Consultancy Services, Infosys, HCL, Wipro, Mahindra Satyam, Birlasoft, Cognizant and a host of other companies based in India are exhibiting in the pavilion. This is a pleasant surprise from JavaOne which typically does not see these many companies out of India.
  • Poker, Ducati, Glider, Beatles Guitar, Sumo wrestler, Callaway Golf, Mini Cooper and other similar sightings were spotted. Check out complete set of images here.
  • Lot more attendees are wearing a suit, quite unlike JavaOne or RailsConf which is typically denim/t-shirt rich.

On a personal front, everything that possibly could went wrong as part of the demo installation yesterday and rehearsal for my talks earlier today. NetBeans was not able to connect to the Oracle database (couple of machine restarts solved that), GlassFish Tools Bundle for Eclipse was timing out attempting to start GlassFish (removing workspace solved that problem), NetBeans's RESTful tooling not recognizing JPA entities, and also found a blocking bug (issue #10166) in deploying Rails app to latest GlassFish promoted build. These demos have worked seamlessly for me all the time time and fortunately worked well during the talk.

My talk at the Unconference on Creating Quick and Powerful Web applications with Oracle, GlassFish and NetBeans/Eclipse went well. It was truly an unconference event with no projector or mic in the presentation room. But the small attendance allowed us to huddle around the table and luckily all the demos worked seamlessly. The slides are available at:

Several demos shown in the talk are available at:

The slides have pointers to several other demos as well. Also showed the simplicity of Java EE 6 development using Eclipse in Java Platform, Enterprise Edition: The Foundation and Future of Your Enterpise.

The day concluded with OTN Night in Howard St tent. Check out a brief video from the event:

Here are some pictures from earlier today:

And the evolving album at:



If you are not able to attend in person, then you can follow OOW Blogs, Open World Live, @OpenWorld (twitter), Community tweets with #oow.

Back tomorrow on Day 3 with more pictures :-)

Technorati: conf oracle openworld oow glassfish javaee netbeans eclipse


Sunday Oct 11, 2009

Oracle Open World 2009 - Day 1 Report

Sun Microsystems is the innovation sponsor of Oracle Open World 2009. And that's what was the theme of Scott McNealy's keynote on a "Sun"day. It's been a while that I've seen Scott on the keynote stage and it truly was an enjoyable experience. In his characteristic way, he gave top 10 reasons that "Engineers have gone wild" as:

10. Who needs thumb drive in the shape of sushi ?
9. "Noble prize" recently awards for gas mask bra - no more ridiculous than other noble prizes recently awarded
8. OS/2
7. Patent awarded for face mask with voice modification capability
6. I could do an entire top 10 of worlds strangest keyboards (strangest being iPhone, "Friends don't let friends type on iPhone")
5. Windows 7
4. Man uses SPARCstation for his ashses
3. New market in "family size' plots
2. Mainframe running Linux
1. Some one came up with this crazy idea for a 'Java Ring'

And then on a more serious note, and keeping with the keynote theme, top 10 innovations from Sun:

10. NFS/PC-NFS Technology (1983)
9. SPARC (1989)
8. Open Source Software (Berkeley Unix, "Red Hat of Berkeley Unix", #1 contributor to OSS community)
7. BSD + UNIX System 5 = Solaris
6. Java (Java card, EE/SE/ME, JavaFX)
5. E10K (64-way Solaris, no longer mainframe required)
4. ZFS/Open Storage/Flash (Exadata)
3. Project Blackbox, world's first modular datacenter
2. SunRay
1. Chip multithreading "CoolThreads"

And the biggest innovation from Sun:

Kicked Butt
Had Fun
Didn't CHeat
Loved our customers
Changed computing for ever

Scott explained why SPARC, Solaris, MySQL, Java are here to stay. "Kick Butt, Have Fun" is truly the spirit at Sun :-)

James Gosling, the father of Java, showed up on the stage to talk about Java's relevance for Oracle. Also showed "The Gospel of Java according to James" and the video is shown below:

John Fowler talked about several brand new Sun/Oracle world-record benchmarks. A key point from these benchmarks "Oracle and Sun were able to set the world record using 1/8th the hardware that IBM used for its largest benchmark". And we also announced F5100 Flash Array, the world's fastest solid-state flash array.

And here are some quotes from Larry Ellison's keynote appearance:

  • "SPARC is a fantastic technology"
  • "All Oracle software runs reliably and faster on Solaris, than ever before"
  • "MySQL competes in different market", "We are going to spend more, not less, on MySQL", "Increase our rate of contribution to that product"
  • "Not only invest in Sun technology, also in Sun business"
  • IBM: Slower, Costs More, Not Fault Tolerant, Not Very Green (from a slide)
  • 25% more throughput, (can do lot better), 16x better response time
  • "IBM's processor is called "POWER", we know why ?" (because it's consumes the entire power of your data center ;-)
  • "I'm not fair on IBM because they are not here to respond"
  • One mans' SUNset is another man's SUNrise, We think this is SUNrise time"

It totally reminded me of Scott McNealy's "dot-not" (as compared to .NET) and "c-flat" (for C#) quotes from JavaOne :-)

Check out related articles about Sun's presence at Open World:

Here are some pictures:

And the evolving album at:



If you are not able to attend in person, then you can follow OOW Blogs, Open World Live, @OpenWorld (twitter), Community tweets with #oow.

On a personal note, this is my first Open World and am totally amazed by the size of attendees, and it's only a Sunday. The entire Howard St is shutdown and tents are installed to accommodate the conference. All 3 Moscone halls (North, South, and West) are used. A scale down replica of Larry's "Rising Sun" is also displayed on Howard Street. And for the first time in 10 years, I'm getting only an Exhibitor badge at Moscone :-)

Also installed GlassFish, NetBeans/Eclipse demos on the booth machine and ready to wow the audience with Java EE 6 in the exhibitor hall for the next 3 days! And of course, I'm talking at the Unconference tomorrow at 11am on Creating Quick and Powerful Web applications with Oracle, GlassFish and NetBeans/Eclipse. Get ready to see lots and lots of demos!

Back tomorrow with more pictures :-)

Technorati: conf oracle openworld oow glassfish netbeans eclipse


Sunday Oct 04, 2009

Silicon Valley Code Code Camp 2009 Trip Report

The Foothill college was sprawling with developers, architects, engineers, et al from all over the San Francisco Bay Area to attend the Silicon Valley Code Camp 2009. This was my third speaking engagement (2008, 2007) and the code camp has certainly matured over the last years. The attendance is steadily growing and the quality of sessions is become more mature as well.

I presented on Java EE 6, GlassFish, and Eclipse Tooling for GlassFish/Java EE 6 and the slides are available below:

and

Both the talks were demo intensive and showed Deploy-on-Save, Preserving session state across deployments, Java EE 6 wizards in NetBeans (1, 2, 3, 4, 5) and Eclipse (1, 2, 3), Metro JAX-WS Web services development in Eclipse, GlassFish v3 Monitoring, GlassFish v3 REST interface to management and monitoring and many others. All the demos are available as screencasts and/or blog entries and the complete set of links are listed in the presentations.

Here are some pictures from the event:

And the complete album at:

That's it folks, see ya next year!

Technorati: siliconvalleycodecamp svcc glassfish javaee eclipse

Monday Sep 14, 2009

TOTD #103: GlassFish v3 with different OSGi runtimes – Felix, Equinox, and Knoplerfish

GlassFish v3 uses standard OSGi APIs to achieve modularity. It bundles Apache Felix 2.0 as the OSGi runtime and can run on any other OSGi R4.1 compliant runtimes as well. This blog will use previously described instructions and show how to run GlassFish v3 on Eclipse Equinox and Knoplerfish. The complete details about different OSGi runtimes is described here, this TOTD provide detailed steps and overrides the instructions defined here (and here and here).

This blog is using a CI build from last week but you should try the instructions on a promoted build.

GlassFish with Felix - Felix 2.0.0 is bundled with GlassFish v3 and requires no additional configurations.

  1. Start GlassFish as:
    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >./bin/asadmin start-domain --verbose
    

    and see the following messages in the log:
    Sep 11, 2009 4:41:16 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
    INFO: Launching GlassFish on Felix platform
    
    Welcome to Felix
    ================
    
    . . .
    
    Sep 11, 2009 4:41:30 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: GlassFish v3  startup time : Felix(9669ms) startup services(4453ms) total(14122ms)
    
    
  2. Optionally, connect to Felix runtime using Apache Felix Remote Shell (described here) as:

    ~/tools/glassfish/v3/2269/glassfishv3 >telnet localhost 6666
    Trying ::1...
    telnet: connect to address ::1: Connection refused
    Trying fe80::1...
    telnet: connect to address fe80::1: Connection refused
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '\^]'.
    
    Felix Remote Shell Console:
    ============================
    
    ->
    


    and type "help" to see the list of commands available as:

    -> help
    bundlelevel
    cd
    find
    headers
    help
    inspect
    install
    log
    ps
    refresh
    resolve
    shutdown
    start
    startlevel
    stop
    uninstall
    update
    version
    
    Use 'help ' for more information.
    
  3. See the list of OSGi modules installed as:
    -> ps
    START LEVEL 1
       ID   State         Level  Name
    [   0] [Active     ] [    0] System Bundle (2.0.0)
    [   1] [Active     ] [    1] HK2 OSGi Main Bundle (0.3.91)
    [   2] [Installed  ] [    1] EclipseLink Core (2.0.0.v20090821-r4934)
    [   3] [Resolved   ] [    1] Hibernate validator library and Validation API (JSR 303) repackaged as OSGi and HK2 bundle (3.0.0.JBoss-400Beta3)
    [   4] [Installed  ] [    1] Connector (gluecode) for GlassFish Java EE Connector Architecture Runtime (3.0.0.SNAPSHOT)
    [   5] [Active     ] [    1] GlassFish Flashlight Framework (3.0.0.SNAPSHOT)
    
    . . .
    
    [ 201] [Resolved   ] [    1] glassfish-corba-asm (3.0.0.b024)
    [ 202] [Resolved   ] [    1] MIME streaming extension (1.4)
    [ 203] [Installed  ] [    1] Admin Console Connectors Plugin (3.0.0.SNAPSHOT)
    [ 204] [Installed  ] [    1] Apache Felix Shell TUI (1.4.0)
    [ 205] [Resolved   ] [    1] org.glassfish.core.glassfish-extra-jre-packages
    
  4. Use "headers" command to display the bundle header properties for any bundle. "help <command>" shows more information about each command displayed in the output of "help". Finally type "exit" to quit the shell.

GlassFish on Equinox

  1. Download Equinox latest release from http://www.eclipse.org/equinox/ (3.5 as of this writing).
  2. Unzip the contents and copy the Equinox jar file to "osgi/equinox" directory of GlassFish as shown below:
    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >unzip ~/Downloads/equinox-SDK-3.5.zip -d ~/tools/equinox-3.5
    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >cp ~/tools/equinox-3.5/plugins/org.eclipse.osgi_3.5.0.v20090520.jar ./osgi/equinox
    
    
  3. Start GlassFish as:
    ~/tools/glassfish/v3/2269/glassfishv3 >GlassFish_Platform=Equinox ./bin/asadmin start-domain --verbose
    

    and see the following messages in the log:
    Sep 11, 2009 5:11:13 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
    INFO: Launching GlassFish on Equinox platform
    Listening on port 6667 ...
    
    . . .
    
    Sep 11, 2009 5:11:19 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: GlassFish v3  startup time : Equinox(3649ms) startup services(1843ms) total(5492ms)
    


    Note, Equinox platform started on port 6667 for remote management.
  4. Optionally, connect to Equinox runtime as:

    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >telnet localhost 6667
    Trying ::1...
    Connected to localhost.
    Escape character is '\^]'.
    
    osgi>
    
    

    Make sure to use the port number specified during the startup. Type "help" to see the list of commands available as:
    osgi> help
    ---Controlling the OSGi framework---
            launch - start the OSGi Framework
            shutdown - shutdown the OSGi Framework
            close - shutdown and exit
            exit - exit immediately (System.exit)
            init - uninstall all bundles
            setprop = - set the OSGi property
    ---Controlling Bundles---
    
    . . . 
    
    ---Controlling the Console---
            more - More prompt for console output
            disconnect - Disconnects from telnet session
    
  5. See the list of OSGi modules installed as:
    osgi> ss
    
    Framework is launched.
    
    id      State       Bundle
    0       ACTIVE      org.eclipse.osgi_3.5.0.v20090520
                        Fragments=62, 128, 205
    1       ACTIVE      com.sun.enterprise.osgi-main_0.3.91
    2       RESOLVED    org.eclipse.persistence.core_2.0.0.v20090821-r4934
                        Fragments=136
    
    . . . 
    
    203     RESOLVED    org.glassfish.admingui.console-jca-plugin_3.0.0.SNAPSHOT
    204     RESOLVED    org.apache.felix.shell.tui_1.4.0
    205     RESOLVED    org.glassfish.core.glassfish-extra-jre-packages_0.0.0
                        Master=0
    

    Typing "help" shows a comprehensive list of commands. Finally type "disconnect" to terminate the shell. Do not type "exit" as it terminates the Equinox shell and killing the GlassFish process as well.

GlassFish with Knoplerfish - As mentioned here, GlassFish v3 requires at least R4.1 APIs. All Knopflerfish releases prior to 3.0.0 are R4 compliant and so will not work with the GlassFish v3 latest builds. Knopflerfish 3.0.0 beta1 is the first build that is R4.2 compliant but it does not start on Mac OS X 10.5.8 as described in issue #2858798. So until then, you you can follow the instructions documented at  GlassFish v3 on OSGi KnopflerFish and Using KnopflerFish Desktop in GlassFish v3 to get them running on GlassFish v3 TP2 or Prelude.

Some additional details missing form the entries above

  1. Download Knoplerfish 2.3.3 and install.
  2. In "knopflerfish_osgi_2.3.3/knopflerfish.org/osgi", copy "props.xargs" to "gf.xargs" and add the lines mentioned here. Make sure to copy the Knopflerfish related files to the modules directory and change the location accordingly.
  3. Create "gfpackages.txt" by copying "felix/conf/config.properties" from the GlassFish directory. List each package specified in the "gf-packages" property on a single line. There should be no other character such as ";" or "," or "/" on a line, only the package name.
  4. Start GlassFish as:
    ~/tools/glassfish/v3/2269/glassfishv3/glassfish >KNOPFLERFISH_HOME=/Users/arungupta/tools/knopflerfish_osgi_2.3.3/knopflerfish.org/osgi GlassFish_Platform=Knopflerfish ./bin/asadmin start-domain --verbose
    
    
    and see the following messages in the log:
    Knopflerfish OSGi framework, version 4.1.10
    Copyright 2003-2009 Knopflerfish. All Rights Reserved.
    
    See http://www.knopflerfish.org for more information.
    Loading xargs url file:/Users/arungupta/tools/knopflerfish_osgi_2.3.3/knopflerfish.org/osgi/gf.xargs
    Removed existing fwdir /Users/arungupta/tools/knopflerfish_osgi_2.3.3/knopflerfish.org/osgi/fwdir
    Installed: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/tiger-types-osgi-0.2.1.jar (id#1)
    Installed: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/auto-depends-0.2.1.jar (id#2)
    Installed: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/config-0.2.1.jar (id#3)
    
    . . .
    
    Started: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/cm_all-2.0.1.jar (id#7)
    Started: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/console_all-2.0.1.jar (id#8)
    Started: file:/Users/arungupta/tools/glassfish/v3/glassfishv3-tp2/glassfish/modules/desktop_all-2.3.11.jar (id#11)
    


    and finally see the Knopflerfish console as:



The instructions will be updated after a more stable release of Knopflerfish is available.

A complete archive of all the tips is available here.

Technorati: totd glassfish v3 osgi apache felix eclipse equinox knopflerfish

Sunday Sep 13, 2009

TOTD #102: Java EE 6 (Servlet 3.0 and EJB 3.1) wizards in Eclipse

The Eclipse community's WTP release with Java EE 6 support has been delayed to Jun 2010. So how do you do Java EE 6 development in Eclipse until then ?

The GlassFish team is trying to bridge the gap by adding new Java EE 6 wizards that allows you to create Servlet 3.0- (JSR 315) and EJB 3.1- (JSR 318) compliant artifacts. So for the first time, in Eclipse, a Java EE 6 application can be created using the GlassFish plugin for Eclipse (ver 1.0.32)! GlassFish v3 is the Java EE 6 in making and so Eclipse and GlassFish v3 together provides you a good environment for your Java EE 6 development.

This Tip Of The Day (TOTD) explains how to use those wizards using Eclipse 3.4.2. If you have an earlier version of plugin already installed then update it as described in TOTD #66. Make sure to use ver 1.0.33 (recently released) if you are using Eclipse 3.5.x. If you have an earlier version of GlassFish plugin installed, then you may have to start Eclipse with "-clean" flag, basically as "eclipse -clean", after updating the plugin. This will allow the environment to detect the new plugins.

  1. Using Eclipse 3.4.2, install the latest GlassFish Eclipse plugin (ver 1.0.32 or higher) in "Eclipse IDE for Java EE developers" as explained in screencast #28. The correct version snapshot is shown below:



    Install latest GlassFish v3 promoted build (62 as of this writing):



    specify the location:



    and click on "Finish" to complete the install. Make sure to select "JVM 1.6.0" as the Java Runtime Environment as that is the minimum requirement for GlassFish v3.
  2. Create a new "Dynamic Web Project" named "ee6".
  3. Add Servlet 3.0 using wizard
    1. Right-click on the project, select "New", "Other ...", expand the "GlassFish" section and select "Web Servlet (Java EE 6)" as shown below:



      and click on "Next >".
    2. Specify the package name as "server" and servlet name as "HelloServlet" as shown below:



      and click on "Finish".
    3. The generated code looks like as shown:



      Notice the usage of "javax.servlet.annotation.WebServlet" annotation to specify the servlet name and url pattern. Also note that no new entries are made in "WEB-INF/web.xml".
    4. Add a new method in the code as:
      protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws IOException {
              ServletOutputStream out = response.getOutputStream(); 
              out.print("<html><body>");
              out.print("Request received at: " + request.getContextPath());
              out.print("</body></html>");
        }
      


      and invoke this method from both doGet(...) and doPost(...).
    5. Right-click the project, select "Run As", "Run on Server" and select the recently added GlassFish server as shown below:



      and click on "Finish". This shows the default page "http://localhost:8080/index.jsp". Change the URL to "http://localhost:8080/ee6/HelloServlet" to see the output as:

    6. The "web.xml" and "sun-web.xml" can be conveniently deleted from "WebContent", "WEB-INF" and the deployed page will continue to function as expected because all the information is captured in annotations instead of the deployment descriptors.
  4. Add an EJB 3.1-compliant session bean
    1. Select "New", "Other ...", expand the "GlassFish" section and select "Session Bean (Java EE 6)" as shown below:



      The important difference to note is that using this new wizard an EJB can now be packaged in a Web project instead of creating a separate "EJB Project".
    2. Specify the package name as "server" and class name as "HelloBean" as shown below:



      The bean type can be chosen from "Stateless", "Stateful" or "Singleton" and appropriate annotations are added accordingly and click on "Finish".
    3. Add a simple method to the generated bean as:
      public String sayHello(String name) {
              return "Hello " + name;
      }
      
    4. Inject a client in the servlet as:
      @EJB HelloBean bean;
      

      and call the business method on EJB as:
      protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws IOException {
              ServletOutputStream out = response.getOutputStream();
              out.print("<html><body>");
              out.print("Request received at: " + request.getContextPath());
              out.print("<br>" + bean.sayHello("Duke"));
              out.print("</body></html>");
       }
      

      and see the response as:



      This new EJB wizard is different from the one that already exists in Eclipse in the following ways:
      1. Singleton session bean can be created
      2. Local interface is off by default
      3. Allows a session bean in a Web project
      4. Simplified wizard flow

So we built a Java EE 6 application using the newly added Servlet 3.0 and EJB 3.1 wizards in GlassFish Plugin for Eclipse.

Please send your feedback and questions to users@glassfishplugins.dev.java.net. Let us know what other Java EE 6 features you'd like to see in Eclipse.

A complete archive of all the tips is available here.

Technorati: totd glassfish v3 eclipse javaee servlet3 ejb

Tuesday Sep 01, 2009

Java EE 6, GlassFish, Eclipse, Dynamic Languages & Web Frameworks at Silicon Valley Code Camp 2009

Silicon Valley Code Camp 2009
To the community, By the community, For the community

Here is the list of GlassFish related sessions:

  1. Java EE 6 and GlassFish v3: Paving the path for future
  2. Using Eclipse for Java EE 6 development for the GlassFish™ Application Server
  3. Dynamic Languages & Web Frameworks in GlassFish

The detailed agenda for each session is explained here.

Here are the coordinates:

Date: Oct 3/4, 2009
Venue: Foothill College, Los Altos, CA
Cost: Free but registration required

Read the trip reports from 2008 and 2007.

With more than a month to go, already 120 sessions have been submitted and 855 attendees registered. The final agenda is not ready yet but typically all Java sessions are on a single day.

It's a free event, with free coffee, food and lots of networking. What's there to loose ?

See ya there!

Technorati: siliconvalleycodecamp glassfish javaee6 eclipse

Sunday Aug 30, 2009

TOTD #99: Creating a Java EE 6 application using MySQL, JPA 2.0 and Servlet 3.0 with GlassFish Tools Bundle for Eclipse

TOTD #97 showed how to install GlassFish Tools Bundle for Eclipse 1.1. Basically there are two options - either install Eclipse 3.4.2 with WTP and pre-bundled/configured with GlassFish v2/v3, MySQL JDBC driver and other features. Or if you are using Eclipse 3.5, then you can install the plug-in separately and get most of the functionality.

TOTD #98 showed how to create a simple Metro/JAX-WS compliant Web service using that bundle and deploy on GlassFish.

This Tip Of The Day (TOTD) shows how to create a simple Java EE 6 application that reads data from a MySQL database using JPA 2.0 and Servlet 3.0 and display the results. A more formal support of Java EE 6/Servlet 3.0 is coming but in the meanwhile the approach mentioned below will work.

Lets get started!

  1. Configure database connection - The key point to notice here is that the MySQL Connector/J driver is already built into the tool so there is no need to configure it explicitly.
    1. From "Window", "Show Perspective", change to the database perspective as shown below:

    2. In the "Data Source Explorer", right-click and click on "Database Connections" and select "New ...":

    3. Search for "mysql" and type the database name as "sakila":



      This blog uses MySQL sample database sakila. So please download and install the sample database before proceeding further.
    4. Click on "Next >" and specify the database configuration:



      Notice the "Drivers" indicate that the JDBC driver is pre-bundled so there is no extra configuration required. If you are using a stand-alone Eclipse bunde and installing the plugin separately, then you need to configure the MySQL JDBC driver explictily.

      The URL indicates the application is connecting to the sakila database. Click on "Test Connection" to test connection with the database and see the output as:



      and click on "Finish" to complete. The expanded database in the explorer looks like:



      The expanded view shows all the tables in the database.
  2. Create the Web project & configure JPA
    1. Switch to JavaEE perspective by clicking "Window", "Choose Perspective", "Other ..." and choosing "Java EE".
    2. Create a new dynamic web project with the following settings:



      Only the project name needs to be specified and everything else is default. Notice the target runtime indicates that this is a Java EE 6 application. Click on "Finish".
    3. Right-click on the project, search for "facets" and enable "Java Persistence" as shown below:

    4. Click on "Further configuration available ..." and modify the facet as shown below:



      Make sure to disable "orm.xml" since we are generating a standard Java EE 6 web application. Choose "sakila" as the database. Click on "OK" and again on "OK" to complete the dialog.
  3. Generate the JPA entities
    1. Right-click on the project, select "JPA Tools", "Generate Entities" as shown:

    2. Choose the schema "sakila":



      and click on "Next >". If no values are shown in the schema drop-down, then click on "Reconnect ...".
    3. Specify a package name for the generated entities as "model" and select "film" and "language" table:



      and click on "Finish". The "film" and "language" table are related so it would be nice if all the related tables can be identified and picked accordingly.

      Anyway this generates "model.Film" and "model.Language" classes and "persistence.xml" as shown below:



      Also notice that "web.xml" and "sun-web.xml" have been explicitly removed since they are not required by a Java EE 6 application.
    4. "model.Film" class needs to modified slightly because one of the columns is mapped to "Object" which is not a Serializable obect. So change the type of "specialFeatures" from Object to String and also change the corresponding getters/setters accordingly. The error message clearly conveyed during the initial deployment and so could be fixed. But it would be nice to generate the classes that will work out-of-the-box.
  4. Create a Servlet client to retrieve/display data from the database
    1. Right-click on the project, select "New", "Class" and specify the values as:



      and click on "Finish". This class will be our Servlet client.
    2. Change the class such that it looks like:
      @WebServlet(urlPatterns="/ServletClient")
      public class ServletClient extends HttpServlet {
        @PersistenceUnit
        EntityManagerFactory factory;
      
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
               throws ServletException, IOException {
          ServletOutputStream out = resp.getOutputStream();
          List list = factory.createEntityManager().createQuery("select f from Film f where f.title like 'GL%';").getResultList();
          out.println("<html><table>");
          for (Object film : list) {
            out.print("<tr><td>" + ((Film)film).getTitle() + "</tr></td>");
          }
          out.println("</table></html>");
        }
      }
      

      and the imports as:
      import java.io.IOException;
      import java.util.List;
      
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.PersistenceUnit;
      import javax.servlet.ServletException;
      import javax.servlet.ServletOutputStream;
      import javax.servlet.annotation.WebServlet;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      
      import model.Film;
      
      
      Basically, this is a Servlet 3.0 specification compliant Servlet that uses @WebServlet annotation. It uses @PersistenceUnit to inject the generated JPA Persistence Unit which is then used to query the database. The database query return all the movies whose title start with "GL" and the response is displayed in an HTML formatted table.
    3. Right-click on the project and select "Run As", "Run on Server" and select GlassFish v3 latest promoted build (this blog used build 61) as:



      and click on "Finish". The output at "http://localhost:8080/HelloJPA/ServletClient" looks like:

Simple, easy and clean!

How are you using Eclipse and GlassFish - the consolidated bundle or standalone Eclipse + GlassFish plugin ?

Download GlassFish Tools Bundle for Eclipse now.

Please send your questions and comments to users@glassfishplugins.dev.java.net.

Please leave suggestions on other TOTD that you’d like to see. A complete archive of all the tips is available here.

Technorati: glassfish eclipse mysql jpa database

Monday Aug 24, 2009

TOTD #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse


Now that you've installed GlassFish Tools Bundle for Eclipse 1.1, lets use this bundle to create a simple Metro/JAX-WS compliant Web service and deploy on GlassFish. These steps will work with either Eclipse 3.4.2 or 3.5 with WTP Java EE support.

  1. Lets create a simple "Dynamic Web Project" as shown below:


  2. Name the project "HelloMetro" and take all other defaults:



    Click on "Finish" to complete the project creation.
  3. Metro allows to create a Web service from a POJO class. So let's add a POJO to the project by right-clicking on the project and selecting "New", "Class" as shown below:

      

    Specify the package name as "server", class name as "HelloService" and click on "Finish".
  4. Add a simple method to the newly generated class as:

    public String sayHello(String name) {
          return "Hello " + name + "!!";
    }
  5. Expand the project, go to "HelloService.java" in "server" package, right-click, select "Web Services", "Create Web service".
  6. Click on "Web service runtime: Apache Axis" and select "Metro (JAX-WS) Runtime" as the Web service runtime as shown below:

  7. Move the slider on the left to top. This will enable testing of the deployed Web service. The completed configuration looks like:



    and click on "Next >".
  8. Select the checkbox "Copy Metro library jars to the project" to resolve the references correctly as shown below:



    and click on "Next >". This bundles the application and deploys to GlassFish and provides an option to test the deployed Web service as shown below:



    Clicking on the "Launch" button shows the following output in the browser:



    The WSDL is hosted at "http://localhost:8083/HelloMetro/HelloServiceService?wsdl".
  9. Click on "sayHello" method, click on "Add" and enter the value as "Duke" as shown below:



    Click on "Go" and the response is shown as:



    Clicking on "Source" in the response window shows the SOAP request/response messages as shown below:

  10. Alternatively, you can click on "Finish" to complete the dialog. Then click on "Run" menu item, "Launch the Web Services Explorer" to see a screen as:



    Enter the URL of the WSDL in "WSDL URL" box as "http://localhost:8083/HelloMetro/HelloServiceService?wsdl" and click on "Go". Now you are seeing the similar screen to test the Web service within the integrated browser as shown below:


A future blog will cover how to write a database-enabled application using the bundled Dali JPA Tools and MySQL pre-registered JDBC driver.

Please send your questions and comments to users@glassfishplugins.dev.java.net.
Please leave suggestions on other TOTD that you'd like to see. A complete archive of all the tips is available here.

Technorati: totd glassfish eclipse galileo webservices metro jax-ws

Friday Aug 21, 2009

TOTD #97: GlassFish Plugin with Eclipse 3.5


A new version of GlassFish Tools Bundle for Eclipse (ver 1.1) was recently released. The build contains
  • Eclipse 3.4.2 IDE with WTP Java EE support
  • GlassFish v2.1 pre-registered and configured
  • GlassFish v3 Prelude pre-registered and configured
  • JavaDB sample database pre-registered and configured
  • GlassFish Plugin (1.0.29)
  • MySQL JDBC driver registered to the IDE
  • Maven m2 plugins
  • JAX-WS Metro plugin
  • GlassFish documentation
  • And optionally, a JDK 1.6.
The functionality is also available in GlassFish Plugin that can be installed on Eclipse 3.5. However because of the Eclipse bug #280365, the plugin cannot be installed directly using Server Adapters. The alternative is to install explicitly using the Update Site. The instructions to do the same are given below:
  1. In "Help", "Install New Software", click on "Available Software Sites":

  2. Search for "ajax" to see the output as:

  3. Click on "Enabled" button to enable the site and see the change as below:



    click on "OK".
  4. Expand the drop-down list box and chose the recently added "update site" as shown below:



    and it shows all the software available from that site as:

  5. Take the defaults, click on "Next" and it shows the GlassFish plugin version number as shown below:

  6. Click on "Next", accept the license by clicking on  "I accept ..." and click on "Finish" to start the installation.



    The IDE restarts after the installation is complete.
  7. Now a new server can be added using "Servers" tab and it shows GlassFish as an option as shown below:

The screencast #28 shows how to create a simple web application using GlassFish v3. Future blogs will show how to leverage the new functionality of JAX-WS Web services plugin and JPA Dali Tooling with GlassFish.

Please leave suggestions on other TOTD that you'd like to see. A complete archive of all the tips is available here.

Technorati: totd glassfish eclipse galileo
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

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