Miles to go …

March 11, 2010

DevNexus 2010 Trip Report

Filed under: eclipse, glassfish, javaee, netbeans — arungupta @ 9:20 pm
As mentioned earlier, I presented on Java E 6 & GlassFish v3 at DevNexus earlier this week. This is an annual conference by Atlanta Java Users Group and had three parallel tracks.

The conference was a sold out and the attendees packed Cobb Galleria conference rooms on both the days.

Anyway, the slides from my session are available below:

The speaking slots were bigger than normal, 70 minutes as opposed to normally 45 or 50 minutes. So that allowed to spend more time on the demos and show all the simplicity and ease-of-use with Java EE 6.  Optional "web.xml" is particularly well appreciated :-) And the attendees were hopeful that other vendors will start supporting Java EE 6 soon. For the record – Caucho, Geronimo, JBoss, and WebLogic have announced plans to be Java EE 6 compliant.

If you are interested in learning about Java EE (and several other topics), then GCA.net offers several of them all over the country. You can even avail a 10% on any class by registering at gca.net/devnexus. And if you are interested in specific learning paths on Java EE 6, then Oracle University has well designed courses.

Personally, I got to meet Dan Allen, Burr Sutter, James Ward, Venkat Subramaniam and many others. Burr is always an energetic personality and was live tweeting photographs of all the speakers. I loved his opening statement that DevNexus is about people who do what needs to be done, not who thinks what needs to be done. Basically he was joking on differences between "architects" and "developers" ;-) I also had some brief discussions with Dan on how Java EE adoption is important for the enterprise. His presentation on Contexts & Dependency Injection explained the concepts in simple manner. HIs slides should be soon available on Seam Wiki. Venkat’s keynote on Tuesday morning on "Facts and Fallacies of Software Development" was quite animated and simply superb. Here are some quotes from his talk:

  • A professional who doesn’t learn to fail, fails to learn
  • If a language is more typed, you type less (e.g. Scala). If a language is less typed, you type more (e.g. Java)
  • Standardization before innovation is a bad idea, that’s why EJB 1.0 suck so bad
  • It’s the lack of clear business objective, not lack of money & time that leads to failure
  • Passion, Competency, Responsibility – 3 things that can make your company succeed

I’m certainly looking forward to his keynote at Spark IT 2010 next week.

Finally some pictures from the conference:

And the complete album is available at:

Here is a brief number summary of the 2-week conference circuit starting next week:

  • 3 conferences
  • 8 sessions + 1 hands-on workshop
  • 2 cities
  • 6 days
  • 3 Hotels
  • 3 Airlines
  • Infinite meet/greet sessions

And then of course there is another one on Java EE 6 & GlassFish in Dallas on April 5, thank you GCA :-)

Technorati: conf glassfish v3 javaee atlanta devnexus ajug gca

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

March 3, 2010

Java EE 6 & GlassFish – Spark IT 2010, Ruby Conf India 2010, Tech Days 2010

Filed under: eclipse, glassfish, javaee, netbeans — arungupta @ 10:19 am

Java EE 6 & GlassFish are swimming across the globe to participate in three different conferences in March 2010.

Spark IT 2010 is an inaugural conference and a joint initiative of CIOL, India’s largest IT portal and PCQuest, India’s leading magazine for IT professionals. You’ll hear about:

  • Java EE 6 & GlassFish (12:05 – 12:50pm, Mar 18)
  • Improving engineering process through Hudson (3:30 – 4:15pm, Mar 18)
  • GlassFish Toolapalooza (2:40 – 3:25pm, Mar 19)
  • Rails on GlassFish workshop (Mar 19)

Check Spark IT 2010 website for the latest updates. See the Agenda, Speakers, Venue Layout, follow the updates on @sparkit2010 and register now!

Ruby Conf India 2010 is India’s first RubyConf and is presented by Ruby community in India (which seems to be growing) and supported by RubyCentral. There are lots of great speakers Matz, Chad, Obie, Nick, and Ola. And of course, you’ll hear about:

  • GlassFish supports multiple Ruby frameworks … really ? (2:00 – 2:45pm, Mar 21)

Check Ruby Conf 2010 website for the latest updates. See the Agenda, Venue (Royal Orchid Hotel), follow the updates on @rubyconfindia and register now!

Don’t miss out on Sambar/Dosa and Mavalli Tiffin Room while in Bangalore :-)

Tech Days 2010 at Hyderabad is biggest of all the Tech Days events. Other than Dum Biryani, Minarets, and Pearls, you’ll hear about Java EE 6 platform and toolshow, OSGi, and Java Persistence API 2. The Agenda (to be updated) has all the details and James Gosling is going to be there as well!

Check Tech Days 2010 website for the latest updates. The venue (Hyderabad International Convention Center) is indeed very impressive so don’t miss out and register now!

Check out reports from Tech Days 2009 (1, 2) and Tech Days 2008 (1, 2, 3, 4, 5, 6, 7).

Here is the current speaking schedule:

And as always, feel free to join me for a run :-)

Technorati: conf glassfish javaee bangalore hyderabad sparkit2010 rubyconfindia techdays hudson

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

February 27, 2010

Oracle at EclipseCon 2010 – Java EE 6, OSGi, GlassFish, EclipseLink, JPA 2.0/Dali, …

Filed under: eclipse, glassfish, javaee, running — arungupta @ 6:34 am
EclipseCon 2010 Oracle is a strategic developer & board member of the Eclipse Foundation and is a gold sponsor of Eclipse Con 2010. See the complete list of Eclipse projects at Oracle.

When ? Mar 22nd – 25th, 2010
Where ? Santa Clara, California
How to register ? Register Now – Use the coupon code ORACLE10 (before Mar 2) for 10% off registration.
What ? Program Schedule

Oracle certainly has a lot to talk about Java EE 6, OSGi/GlassFish, JPA 2.0 and Dali, Future of App Servers, Future of Enterprise Java, Eclipse RT and WTP Reloaded tutorials and many other sessions. See the complete details about Oracle’s participation here.

Also don’t miss the keynote by Steve Harris and Jeet Kaul on Community and Adaptation. Hear these two industry leaders and prolific speakers talk about how Java has empowered community, engendered new forms of adaptation and will continue to blaze the trails.

And then there is Members and Committers reception on Monday evening sponsored by Oracle. Visit us at booth #8 to speak with technical experts, see demos and get information about Oracle’s Eclipse technology and Project participation.

OSGi DevCon 2010 is happening on the same dates/venue and is covered with Eclipse Con registration.

And last, but not the least, let that runner in you have some fun and run with fellow attendees. Yep, there are even prizes!

Keep checking eclipsecon.org for the latest updates.

Unfortunately, I’ll be speaking elsewhere in a different part of the world during exact same dates and so will miss all the fun. More on that later but here are some key members of the Eclipse Foundation:

Feel free to greet and thank them for running the show :-)

Read about 2009 participation here.

Technorati: conf oracle glassfish javaee oepe eclipsecon santaclara

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

January 30, 2010

Developer Tools Strategy by Oracle+Sun: NetBeans & Hudson to stay!

Filed under: eclipse, netbeans — arungupta @ 6:26 am

Hear Ted Farrell, Chief Architect and Senior Vice President talk about Oracle and Sun Java Developer Tools Strategy.

Here is a summary for those who want a quick juice:

  • Productivity With Choice

    • Choose the right tool set for your needs
    • Shared infrastructure across tools with Hudson, Oracle TPC, Subversion. Bugzilla, Maven, etc.
    • NetBeans continues with strong Java focus
    • Combine and integrate the best features across tools
  • More resources for Developers

    • Netbeans.org, java.net, otn.oracle.com
    • More courses/training on Java technologies
    • More conferences around the world
    • Better products from expanded R&D and partner ecosystem
    • Larger combined developer community

Here is a lovely snapshot from the webcast …

Some more detailed points captured from the webcast …

  • If you are a NetBeans user today, you’ll continue to be a NetBeans user after acquisition.
  • Increase the investment in Hudson, lots of synergy with Team Productivity Center.
  • Discontinue the public interface for kenai.com for now, fits very well with some internal projects. Read more about the future of kenai.com.
  • Want to make the best Java IDE for the Java platform. NetBeans platform is very important to lot of customers.
  • For NetBeans, turn to community for external non-Java like Dynamic Languages. Invest more in the infrastructure and community.
  • netbeans.org unchanged
  • Community participation is key for:

    • NetBeans plug-ins
    • Building apps on NetBeans Platform
    • Emerging, Dynamic Languages
    • Dialog, interaction, lists, docs, events, JUGS, etc
  • No licensing changes

    • Versions of NetBeans <= 6.7 follow Sun policy
    • Versions of NetBeans >= 6.8 follow the Oracle policy (complete details)

The webcast also talks about JavaOne being co-located with Oracle Open World (Se 19-23, 2010) and also expanding to Brazil, Russia, India, and China.

oracle.com/tools for more details. The complete list of webcasts + slides from yesterday’s event are now available.

There are several other articles (in no particular order):

Also check out the FAQ for Developer Community.

Technorati: sun oracle netbeans kenai hudson strategy

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

December 4, 2009

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

Filed under: eclipse, glassfish, javaee — arungupta @ 10:00 am

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 their older GlassFish plugin 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 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, 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

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

October 12, 2009

Oracle Open World 2009 – Day 2 Report

Filed under: eclipse, glassfish, javaee, netbeans — Tags: , — arungupta @ 11:01 pm

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

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

October 3, 2009

Silicon Valley Code Code Camp 2009 Trip Report

Filed under: eclipse, glassfish, netbeans — arungupta @ 11:30 pm

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

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

September 14, 2009

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

Filed under: eclipse, glassfish, javaee, totd — Tags: , , , — arungupta @ 2:00 am

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

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

September 1, 2009

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

Filed under: django, eclipse, frameworks, glassfish, grails, javaee, rails — Tags: , — arungupta @ 2:52 am
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

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

August 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

Filed under: eclipse, general, javaee, totd — Tags: , , , , — arungupta @ 11:00 am

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

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Older Posts »

Powered by WordPress