Combining Groovy, Grails, MySQL, and the Java Persistence API (Carol McDonald)

, , , , , July 31st, 2008

Original Source

Carol McDonald has written an excellent article describing how to get a Grails application running based on Sun’s open source technology stack, MySQL in the database end, Glassfish v2 as the server engine, NetBeans 6.1 as the IDE of choice. JPA is also thrown into the mix as the EnterpriseTips site is all about JEE related topics.

With the addition of support for scripting languages in the Java platform, there has been a lot of interest in combining into web applications scripting languages such as Groovy, Java technologies such as the Java Persistence API (JPA), and databases such as MySQL. Last year I wrote a Tech Tip titled Combining JavaServer Faces Technology, Spring, and the Java Persistence API that showed how you can use JavaServer Faces Technology, Spring, and the JPA to create an application that displays an online catalog of pets. In this tip, I’ll show you how to create an online catalog application using the Groovy language, the Grails framework, the MySQL database, and the Java Persistence API.

A package that contains the code for the sample application accompanies the tip. The code examples in the tip are taken from the source code of the sample (which is included in the package). In this tip, you’ll use NetBeans IDE 6.5 Milestone 1 to build the application and deploy it on the GlassFish application server. The NetBeans IDE is a modular, standards-based, integrated development environment (IDE) written in the Java programming language. The latest NetBeans IDE offering, NetBeans IDE 6.5 Milestone 1 (or M1 for short), offers many new features including support for Groovy and Grails. GlassFish is a free, open source application server that implements the newest features in the Java EE 5 platform.

A Summary of the Languages, Technologies, and Frameworks in the Sample Application

If you’re not familiar with Groovy, Grails, MySQL, or the Java Persistence API, here are brief descriptions:

  • Groovy is an agile and dynamic language for the Java Virtual Machine1. It compiles to Java bytecode and combines popular features from languages such as Smalltalk, Python, and Ruby.
  • Grails is an open-source web application framework that leverages the Groovy language and complements Java Web development. It aims to bring the “coding by convention” paradigm to Groovy. Grails is a Model-View-Controller based framework that simplifies the development of web applications by reducing the need for configuration files and by generating a lot of the things needed in a database-backed web application.
  • MySQL is the world’s most popular open-source database. It offers consistently fast performance, high reliability and ease of use.
  • The Java Persistence API provides a (plain old Java object) POJO-based persistence model for Java EE and Java SE applications. It handles the details of how relational data is mapped to Java objects, and it standardizes Object/Relational (O/R) mapping.

The Sample Application

The sample application displays an online catalog of pets sold in a pet store. Figure 1 shows the Catalog Listing page, which allows a user to page through a list of items in a store.

Catalog Listing Page

The article is well balanced, you will find references to common Grails artifacts as controllers, domain classes and views. Carol also shows how the datasource must be configured and the steps you must follow to get the application running. Continue reading the whole article at this link.

Tags: , , , , ,

Creating a Grails Plugin in NetBeans IDE (Geertjan Wielenga)

, , July 23rd, 2008

Original Source

Geertjan Wielenga continues its exploration of the new Groovy/Grails features available in NetBeans 6.5 milestone 1. This time he describes the steps required to create a sample Grails plugin, but he doesn’t stop there, he also describes how to install it in an application and put it to work. With this guide and the other links he mentions you will be able to code your own plugins using NetBeans in no time.

Tags: , ,

Grails Development Made Even Simpler Using NetBeans IDE 6.5 (Meera Subbarao)

, , July 21st, 2008

Original Source

Meera Subbarao writes about her latest testing of Groovy/Grails support with NetBeans 6.5. You may remember Meera from a previous post (Highlights of Beginning Groovy and Grails: From Novice to Professional). She notes that this particular test began as a means to corroborate what Beginning Groovy and Grails proposes: Groovy and Grails increase your productivity. But to have a good level of productivity you require tools, given that Geertjan’s NetBeans to Grails guide was posted during the weekend, she decided to give it a try. In her own words:

After having read the book Beginning Groovy and Grails: From Novice to Professional, I was wondering if it was ever going to be as simple as a few clicks in any IDE for Grails development. Just yesterday, I read an article by Geertjan Wielenga(who is also my colleague at Javalobby/DZone) about how to get started with Grails in NetBeans IDE 6.5 in 5 simple steps. I had worked with NetBeans quite a lot for EJB3 development but I had never used it for either Groovy or Grails; the choice earlier was always Eclipse IDE.

I first followed the Book Demo and later moved to a more real life example. This was a litmus test which I thought NetBeans had to pass for developers to continue using the same for Groovy/Grails development. The example in the book has a few relationships; which is what we would generally have in any enterprise application.
domain-classes
I was able to create all the domain classes, controllers, manage relationships without ever leaving the IDE. Creating a Domain class or even a Controller, is as simple as right clicking on the appropriate nodes and providing meaningful names. The IDE creates the skeleton classes; we need to provide the meat within

If you are a Groovy or a Grails fan, download the latest version of NetBeans and give it a try. You can develop, test and run your Grails application without ever opening a command window. The Groovy editor has basic coloring, formatting and bracket completion. The GSP editor has coloring, highlighting of GSP tags, expressions and scriptlets. You can mix and match Java and Groovy as well.

Tags: , ,

Grails: This Time With Tools (Geertjan Wielenga)

, , July 20th, 2008

Original Source

Geertjan Wielenga, a well known NetBeans advocate and zone leader at Javalobby , has written a detailed step by step guide to run a sample Grails application with the latest NetBeans 6.5 milestone. Go check it out and don’t forget to send feedback to the NetBeans teams in order to get better support for Groovy/Grails in the official release of version 6.5.

Tags: , ,