Arun Gupta, Miles to go ...

Arun Gupta is a technology enthusiast, a passionate runner, and a community guy who works for Sun Microsystems.
Main | Next page »

http://blogs.sun.com/arungupta/date/20091012 Monday October 12, 2009

http://blogs.sun.com/arungupta/date/20091011 Sunday October 11, 2009

http://blogs.sun.com/arungupta/date/20091004 Sunday October 04, 2009

http://blogs.sun.com/arungupta/date/20090915 Tuesday September 15, 2009

http://blogs.sun.com/arungupta/date/20090914 Monday September 14, 2009

http://blogs.sun.com/arungupta/date/20090902 Wednesday September 02, 2009

http://blogs.sun.com/arungupta/date/20090831 Monday August 31, 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

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20090825 Tuesday August 25, 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

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20090821 Friday August 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

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20090708 Wednesday July 08, 2009

FISL 2009 Speaker Certificate


Received a "certificate of attendance as speaker" for recently concluded FISL 10.



This is sweet, thanks FISL organizers! It certainly adds a personal touch to the whole experience.

I don't remember receiving a personal certificate like this :)

Technorati: conf fisl brazil glassfish netbeans mysql eclipse

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20090630 Tuesday June 30, 2009

FISL 2009 Wrapup - 3 talks, 1 talk show, 14 blogs, 10 videos, 275 pics, 2 GlassFish production stories


FISL 2009
wrapped up over the weekend. Even though the conference officially ended on Saturday but the connections made there will certainly allow us to continue all the great momentum. The conference celebrates open source and it was certainly great to see Federal Government and Banks with their booths in the exhibitor halls. The visit by Brazilian President Lula certainly highlights the importance of this conference to the local community. There were booths from Debian, Firefox, Ubuntu and other major open source softwares. Some commercial vendors had a booth as well and of course Sun Microsystems had a big presence with GlassFish, Open Solaris, NetBeans, MySQL and other offerings.

I delivered 3 talks and participated in 1 talk show:

  • Java EE 6 (slides) & Enterprise Features of GlassFish (slides)
  • Creating powerful web applications using GlassFish, MySQL and NetBeans/Eclipse slides
  • Continuous Integration using Hudson (slides)
  • Simon Phipps Talk Show
This blog featured 14 blogs, 10 videos, 275 pictures and 2 GlassFish production stories over the past week. The collage is created from some of the pictures:

FISL 2009 Collage (click to see larger version)

Click on the collage to see a larger version. The complete photo album is available at:



A playlist of all the 10 videos is below:



And now all the 14 blog entries ...
Over all, thoroughly enjoyed the Brazilian spirit and looking forward to next visit!

Many thanks to the Sun Brazil team, especially Bruno Souza, Mauricio Leal, Eduardo Lima, Vitorio Sassi and other Campus Ambassadors!

Technorati: conf brazil fisl javali glassfish netbeans mysql hudson

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20090624 Wednesday June 24, 2009

FISL 2009 Day 1 Report




I presented on "Creating powerful web applications using GlassFish, MySQL and NetBeans/Eclipse" as the first talk of FISL 10 yesterday. The room was only partial full being the first talk of FISL but got packed towards the middle so that was exciting. The slides are available here.

The key message is that NetBeans and Eclipse provide a seamless development/deployment environment for GlassFish.

The several demos shown in the talk are explained at:

And you can find a lot more information on the Portuguese TheAquarium.

The soccer balls at the Sun booth in the pavilion were quite a hit as evident by the video below:


Come by again at Sun booth until the end of conference to get one for yourself :)

There were booths from Debian, Gnome, Firefox, Fedora and a host of other open source projects. There were community booths from local Java User Groups, Linux User Group, Open Solaris User Group and similar efforts. Some government and financial companies that heavily use/promote open source products were also present. And then there were other commercial vendors as well!

Some attendees were playing musical instruments to the local tunes which added to the festive atmosphere in the exhibitor floor. Enjoy the video below:


The day ended with great food at Na Brasa Churrascaria, love the caipirinhas!

Here are some pictures from Day 1:












This is the 10th anniversary of FISL and so here is the timline over the past years as shown in the exhibitor pavilion:






And the evolving album:



See you in few hours at the FISL.

Technorati: conf brazil fisl glassfish mysql netbeans eclipse

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20090617 Wednesday June 17, 2009

GlassFish swimming to FISL, Brazil




FISL stands for "Forum Internacional Software Livre" in the Portuguese language and means "International Free Software Forum" in the English language. The punch line is "A technologia que liberta" and means "The technology that liberates".

This is the biggest event about free software in America and was attended by 7417 participants in 2008.

Just like "Freedom of Speech" is a basic human right, "Freedom of Software" is a basic right for the technology evolution. GlassFish gives you the freedom:
  • To Pick your own framework: Java EE, Ruby-on-Rails, Python/Django, Groovy/Grails, or any other
  • Choose your IDE: NetBeans, Eclipse, IntelliJ and others.
  • Over properietary Application Servers by providing highly reliable and production quality features like
    • Clustering/Load balancing
    • Secure, Reliable, and Transactional, and .NET-interoperable Web services stack (Metro)
    • Easy-to-use web-based administration console along with a powerful CLI
    in an open source world.
  • Offers dual open-source license (CDDL or GPL v2 w/ CPE)
Similarly NetBeans allows you to create Java, Ruby, Python, Groovy, PHP, C/C++, JavaScript, Java EE, Mobile, REST/SOAP, and a variety of applications. Eclipse also provides an open development platform comprised of extensible frameworks, tools and runtimes for building, deploying and managing software across the lifecycle. MySQL is the world's most popular open source database.

Together, GlassFish, NetBeans/Eclipse, and MySQL liberates you from the vendor lock-in by offering you a compelling choice.

At FISL 10, learn how GlassFish, NetBeans/Eclipse, and MySQL provide a powerful feature-rich yet easy to use platform for developing/deploying your web applications. The complete details about the session are available here. I plan to show multiple demos during the talk that you may find useful in your regular work.

Where ? Porto Alegre, Brazil
When ? Jun 24-27, 2009

Click on the map below for coordinates of the venue:



Join the Facebook Group or follow on Twitter @fisl10.

Close to 6000 attendees have registered for FISL so far and am definitely looking forward to feel/enjoy the Brazilian spirit.

To Brazil, Capirinhas, Guaranas, Churascarias, Beaches ... La La La La La La La La La La La La La La La La La La La La La La La La

Drop a comment if you are interested in a meal or run together :)

Technorati: conf glassfish netbeans eclipse mysql fisl brazil

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20090616 Tuesday June 16, 2009

GlassFish at Eclipse Demo Camps Galileo 2009 - Jun 17th


What is an Eclipse Demo Camp ?

The Eclipse DemoCamps are an opportunity to showcase all of the cool interesting technology being built by the Eclipse community. They are also an opportunity for you to meet Eclipse enthusiasts in your city.

The GlassFish team will showcase the seamless integration with Eclipse. Several blog entries are already available at glassfish+eclipse.

Do you know:
  • GlassFish Tools Bundle for Eclipse provide Eclipse 3.4.2 with Java EE support, GlassFish v 2.1 + GlassFish v3 pre-registered/configured, with commercial support
  • GlassFish v3 Preview can be added
  • Screencast #28 shows how develop/debug a web application using Eclipse and GlassFish
  • TOTD #66 shows how to install GlassFish plugin in an existing Eclipse install
  • Eclipse Galileo can be used for GlassFish development/deployment, use "http://ajax.dev.java.net/eclipse" as the udpate site.
Meet us in person and hear the glory:

When ? Jun 17th, 7:30pm - 9:30pm
Where ? Oracle Headquarters, Redwood Shores

Complete details here.

Technorati: conf glassfish eclipse democamp

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20090521 Thursday May 21, 2009

TOTD #83: Eclipse Tools Bundle for GlassFish 1.0 - Now Available!


The GlassFish Tools Bundle for Eclipse 1.0 is now available.



An earlier blog entry explains how to get started using this bundle.

If you used an earlier version (0.99.x) of this bundle, then an upgrade is not supported. However backwards compatibility will be maintained going forward!

Here are some pointers to get you started:

Enjoy and send us feedback at users@glassfishplugins.dev.java.net.

Technorati: glassfish eclipse

del.icio.us | furl | simpy | slashdot | technorati | digg |
|
Main | Next page »

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.