Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Overview

...

Wiki Markup
{redirect:https://www.jetbrains.com/idea/help/getting-started-with-grails.html

...

|delay

...

=0}

IntelliJ IDEA tightly integrates with Grails, and makes it possible to work with Grails applications from within the IDE, sparing you from the need to use command line. Grails support in IntelliJ IDEA lets you do the following:

...

Let’s start from the very beginning, that is, create a new project from scratch. To do that, choose

span
classshortcut
File
New Project
span
classshortcut
Wiki Markup
{span:class=shortcut}File{span}
Wiki Markup
{span:class=shortcut}New Project{span}
on the main menu, or click the New Project icon on the Welcome screen. On the first page of the New Project wizard, in the selector pane, choose Grails. On the right part of the page, enter the necessary information, such as project's name, its location and click Finish:

...

  • Execute a Grails target. Press
    span
    classshortcut
    Ctrl
    +
    span
    classshortcut
    Alt
    + G
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}Ctrl{span}
    +
    Wiki Markup
    {span:class=shortcut}Alt{span}
    +
    Wiki Markup
    {span:class=shortcut}G{span}
    , and enter Grails target name. Note that code completion
    span
    classshortcut
    Ctrl
    +Space
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}Ctrl{span}
    +
    Wiki Markup
    {span:class=shortcut}Space{span}
    is available in the Run Grails target dialog box:

...

  • Right-click the Grails tool window background, and choose
    span
    classshortcut
    New
    Grails Domain class
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}New{span}
    Wiki Markup
    {span:class=shortcut}Grails Domain class{span}
    on the context menu:

As a result, two stub classes are created in the project:

  • Domain class Book.groovy
  • Test class BookTests.groovy
    Note

    IntelliJ IDEA diligently shows all output messages in the console.

    For the purposes of our short guide, we’ll continue working with the domain class Book.groovy. Now it is just a stub, and we want to add the following fields to it:
  • Book title
  • Author name (may be two author names?)
  • Description
  • Publisher
  • Date published
  • Copyright
  • ISBN
  • Reader name
  • Date taken
    Open Book.groovy for editing ( F4
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}F4{span}
    ), and type these fields in your code, using the code completion (
    span
    classshortcut
    Ctrl
    +Space
    span
    classshortcut
    Wiki Markup
    {span:class=shortcut}Ctrl{span}
    +
    Wiki Markup
    {span:class=shortcut}Space{span}
    ):

The next step is to provide a controller and views. Again, you can do it in two ways: either run the Grails target generate-all Book, or use Scaffolding - the handy tool that you can find at the top of the domain class editor:

...

There are more things you might want to do to make your application useful, but let’s try to run it straight away with the default settings. To do that, press

span
classshortcut
Shift
+F10
span
classshortcut
Wiki Markup
{span:class=shortcut}Shift{span}
+
Wiki Markup
{span:class=shortcut}F10{span}
and after a turmoil of messages in the Console, your application starts in your default browser, with the following URL in the address bar: http://localhost:8080/MyGrailsProject/.

...

Finally, if you want to evaluate your effort for creating and running your Grails application under IntelliJ IDEA, view the number of files and lines of source code. Press

span
classshortcut
Ctrl
+
span
classshortcut
Alt
+ G
span
classshortcut
Wiki Markup
{span:class=shortcut}Ctrl{span}
+
Wiki Markup
{span:class=shortcut}Alt{span}
+
Wiki Markup
{span:class=shortcut}G{span}
, type stats in the pop-up window, and see the results in the Console:

...