Lately I've been playing with a couple different frameworks for building web applications. While I haven't really picked one in particular, I've identified pros and cons for each of them. I thought about writing a post that describes something I found last weekend, but I got a little bored with that project and decided to do something else this weekend.
I started building some blogging software - with the limited amount of time I had this weekend. In between running my daughter to her volleyball game, my son to his job, getting groceries and general housekeeping stuff, I was able to get quite a bit done. It was then that I decided I may as well start publishing this as a tutorial . . . just for the fun of it and to document my progress. Not that the Internet needs yet another blog software . . . but that's what this particular project is going to be.
One more thing . . . in case you're curious
I'm using Netbeans as my IDE with Grails 1.1 and MySQL. It has excellent support for Grails, Groovy and all types of files used in web development. While I've been using Java for a while, I don't necessarily consider myself proficient with Groovy. I'm still picking up the finer points of that language.
I'll probably be using the Quartz plug-in as well as one that facilitates Ajax and Rich UI at some point in time. When I need them, I'll add them.
Since I plan on considering this an ongoing tutorial, the first part of the tutorial won't be using a significant amount of Groovy coding - it will be mainly focused on Grails.
What this isn't . . .
I'm not going into detail about installing Netbeans, Grails, MySQL or Java. If you need that there's a plethora of information via Google.
Onward and upward . . .
I started building some blogging software - with the limited amount of time I had this weekend. In between running my daughter to her volleyball game, my son to his job, getting groceries and general housekeeping stuff, I was able to get quite a bit done. It was then that I decided I may as well start publishing this as a tutorial . . . just for the fun of it and to document my progress. Not that the Internet needs yet another blog software . . . but that's what this particular project is going to be.
One more thing . . . in case you're curious
I'm using Netbeans as my IDE with Grails 1.1 and MySQL. It has excellent support for Grails, Groovy and all types of files used in web development. While I've been using Java for a while, I don't necessarily consider myself proficient with Groovy. I'm still picking up the finer points of that language.
I'll probably be using the Quartz plug-in as well as one that facilitates Ajax and Rich UI at some point in time. When I need them, I'll add them.
Since I plan on considering this an ongoing tutorial, the first part of the tutorial won't be using a significant amount of Groovy coding - it will be mainly focused on Grails.
What this isn't . . .
I'm not going into detail about installing Netbeans, Grails, MySQL or Java. If you need that there's a plethora of information via Google.
Onward and upward . . .
So, the following ussumption applies: You have Java, Netbeans 6.5, MySQL and the appropriate .jar file to facilitate database communication between your app and Grails. And, you have Netbeans set up to use Grails.
If you don't have them, get them: Java, Grails 1.1, Netbeans 6.5, MySQL, the mysql.jar ( mysql-connector-java-5.1.7-bin.jar ). You can also get Netbeans that includes Java.
Now, with that out of the way . . . with Netbeans running and open . . . you can see that we have a pretty blank slate.

The first thing we'll do is create a project.
Use either the "New Project" icon or File -> New Project to open the New Project dialog.

Next, name your project using Netbean's default location and folder settings, but change the name to "GroovyBlog."

Voila! We've created our project and Grails has generated all kinds of stuff for us with the default settings. Next thing on our agenda . . . change a couple of those default settings.

The first thing we'll do is modify the database settings:
Grails sets our database settings in the file, "DataSource.groovy." You can find that file in the "Projects" tab of the Netbeans IDE ( in the left pane ) under "Configuration."

A couple of things to do here.
First, make sure that mysql-connector-java-5.1.7-bin.jar is in your "Libraries" ( it is named "lib" ) folder. I generally just manually copy it over to the "lib" directory wherever the project is located. For me this is, "/home/jim/NetBeansProjects/GroovyBlog/lib." It will most likely be different for you depending upon what OS you are using.
Next, make sure you have a database to use. I'm going to assume that you've created a database named, "groovy_blog" You can use whatever username and password you've configured your database to use. Right now, I'm not concerned with a production and test database. We're keeping this basic for now.
With that done, open DataSource.groovy and modify it as shown:
Let's run the app now!!
Click the green arrow icon located in the middle of your toolbar. ( Use can also use F6 ). Netbeans will usually open your web browser to the appropriate web address for your app. Most likely this will be, http://localhost:8080/GroovyBlog/. Provided everything was done correctly you should see the familiar Grails screen.
.
One more thing and we'll call it a day . . .
We're going to modify our layout for the blog. To do this we'll have to modify the file, "main.gsp" under "Views and Layouts/layouts," the "main.css" file under "Web Application/css" and "index.gsp" under "Views and Layouts."
Here's the way my files ended up:
.


Our end result is going to be pretty plain unless you add some styling to those divs and the markup within them. I'm going to let you take care of that yourself.

The next thing we'll do, in the next installment, is add a controller, an action, a view and some domain classes. So, take care of your css and we'll get to some guts in the next tutorial!
As is always the case, I appreciate your feedback in the comments.
Next up, Tutorial #2.
If you don't have them, get them: Java, Grails 1.1, Netbeans 6.5, MySQL, the mysql.jar ( mysql-connector-java-5.1.7-bin.jar ). You can also get Netbeans that includes Java.
Now, with that out of the way . . . with Netbeans running and open . . . you can see that we have a pretty blank slate.

The first thing we'll do is create a project.
Use either the "New Project" icon or File -> New Project to open the New Project dialog.

Next, name your project using Netbean's default location and folder settings, but change the name to "GroovyBlog."

Voila! We've created our project and Grails has generated all kinds of stuff for us with the default settings. Next thing on our agenda . . . change a couple of those default settings.

The first thing we'll do is modify the database settings:
Grails sets our database settings in the file, "DataSource.groovy." You can find that file in the "Projects" tab of the Netbeans IDE ( in the left pane ) under "Configuration."

A couple of things to do here.
First, make sure that mysql-connector-java-5.1.7-bin.jar is in your "Libraries" ( it is named "lib" ) folder. I generally just manually copy it over to the "lib" directory wherever the project is located. For me this is, "/home/jim/NetBeansProjects/GroovyBlog/lib." It will most likely be different for you depending upon what OS you are using.
Next, make sure you have a database to use. I'm going to assume that you've created a database named, "groovy_blog" You can use whatever username and password you've configured your database to use. Right now, I'm not concerned with a production and test database. We're keeping this basic for now.
With that done, open DataSource.groovy and modify it as shown:
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "your_username"
password = "your_password"
}
Now, we've just told Grails to use the MySQL drivers. Now we'll set up our database url:environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
url = "jdbc:mysql://localhost:3306/groovy_blog"
}
}
/*
test {
dataSource {
dbCreate = "update"
url = "jdbc:hsqldb:mem:testDb"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:hsqldb:file:prodDb;shutdown=true"
}
}
*/
}
I've commented out the test and production database environments. It won't really matter for now because we're only concerned with development at this time.Let's run the app now!!
Click the green arrow icon located in the middle of your toolbar. ( Use can also use F6 ). Netbeans will usually open your web browser to the appropriate web address for your app. Most likely this will be, http://localhost:8080/GroovyBlog/. Provided everything was done correctly you should see the familiar Grails screen.
.

One more thing and we'll call it a day . . .
We're going to modify our layout for the blog. To do this we'll have to modify the file, "main.gsp" under "Views and Layouts/layouts," the "main.css" file under "Web Application/css" and "index.gsp" under "Views and Layouts."
Here's the way my files ended up:
.



Our end result is going to be pretty plain unless you add some styling to those divs and the markup within them. I'm going to let you take care of that yourself.

The next thing we'll do, in the next installment, is add a controller, an action, a view and some domain classes. So, take care of your css and we'll get to some guts in the next tutorial!
As is always the case, I appreciate your feedback in the comments.
Next up, Tutorial #2.

Great tutorial! Perhaps you might be interested in 6.7M3 as with 6.5 you could run into issues with Grails 1.1 and plugins.
P.
Thanks for the heads-up Petr. I haven't experienced any problems with plug-ins yet, but then again I've only been using Grails 1.1 since it was released ( stable ) and haven't used many plug-ins with that version.