You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VaadinOnGrailsCreateProjectInIntelliJIDEA.asciidoc 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ---
  2. title: Vaadin On Grails with IntelliJ IDEA
  3. order: 35
  4. layout: page
  5. ---
  6. [[vaadin-on-grails-with-intellij-idea]]
  7. Vaadin on Grails with IntelliJ IDEA
  8. -----------------------------------
  9. _Versions used in this tutorial: Grails 2.3.x, Vaadin 7.1.x. News and
  10. updates about Vaadin on Grails are available on
  11. https://twitter.com/VaadinOnGrails[VaadinOnGrails]_
  12. In this tutorial we will show how to create and setup
  13. http://grails.org/doc/latest/guide/single.html[Grails] project together
  14. with https://vaadin.com/learn[Vaadin], in IntelliJ IDEA. These two
  15. frameworks Grails and Vaadin are integrated together with this
  16. http://grails.org/plugin/vaadin[plugin].
  17. First we need to setup Grails with IDE,
  18. http://www.jetbrains.com/idea/[IntelliJ IDEA 13] in this tutorial. Or we
  19. could get https://spring.io/tools/ggts[Groovy/Grails Tool Suite]
  20. which is without any fees.
  21. [[setup-ide]]
  22. Setup IDE
  23. +++++++++
  24. 1. Go to http://grails.org/download and get the latest version of
  25. Grails
  26. 2. Unpack it on your local computer and start up IntelliJ IDEA
  27. 3. Open the *New Project* window and select Grails from the list. Click
  28. on *Create...* button and then select the root of your unpacked Grails
  29. archive. 
  30. image:http://vaadinongrails.com/img/setup-idea.png[Setup IDEA]
  31. [[create-new-project]]
  32. Create New Project
  33. ++++++++++++++++++
  34. Fill in the name of the project and choose the latest version of Grails.
  35. image:http://vaadinongrails.com/img/new-project.png[Create new project]
  36. Click on *Finish* and on the next dialog, choose **Run 'create
  37. app'**
  38. image:http://vaadinongrails.com/img/create-app-idea.png[Create app IDEA]
  39. Open file `BuildConfig.groovy` and add new plugin as follows:
  40. `compile ":vaadin:7.1.11"`. The latest version of the plugin is always
  41. available on http://grails.org/plugin/vaadin
  42. image:http://vaadinongrails.com/img/build-config-idea.png[Build config IDEA]
  43. We have to disable Grails to take control over the URLs, so Vaadin can
  44. do it. Open `UrlMappings.groovy` file and remove the mapping, so the
  45. content of the file is the following:
  46. ....
  47. class UrlMappings {
  48. static mappings = {}
  49. }
  50. ....
  51. If you see this error, run grails again and compile it again. There an
  52. issue with grails and it is not possible to compile the project in the
  53. first run.
  54. ....
  55. target/work/plugins/vaadin-7.1.11/scripts/_Events.groovy: 1: unable to resolve class com.vaadin.grails.VaadinConfiguration @ line 1, column 1. import com.vaadin.grails.VaadinConfiguration
  56. ....
  57. Now we want Vaadin plugin to generate the mandatory files in order to be
  58. able to run Vaadin application. On the right side in the menu, there is
  59. a launch button, click on that one.
  60. image:http://vaadinongrails.com/img/run-app-idea.png[Run app IDEA]
  61. You can also press `Alt+Cmd+G` on Mac OS or `Ctrl+Alt+G` on Windows and
  62. type `run-app` command there.
  63. Mark `grails-app/vaadin` folder as a source folder in IDE.
  64. image:http://vaadinongrails.com/img/source-folder-idea.png[Source folder IDEA]
  65. Run the application again and a Vaadin application with a single *Home*
  66. label will be available on http://localhost:8080/ria-app in your
  67. browser.
  68. image:http://vaadinongrails.com/img/first-run.png[First run]
  69. [[developing]]
  70. Developing
  71. ++++++++++
  72. All the Vaadin code should be placed in `grails-app/vaadin` folder. All
  73. the other classes that are not UI related can be put to `src/groovy` or
  74. `src/java`.
  75. Open the generated `MyUI.groovy` file, edit the content a bit and save
  76. the file. See that the class has been recompiled and when you refresh
  77. the page, it gets automatically updated. You don't have to restart the
  78. application or use JRebel for small changes. But if we change the
  79. application context, add a new bean, change method signature and other
  80. 'big' changes, we have to restart the application.
  81. image:http://vaadinongrails.com/img/recompile-idea.png[Recompile IDEA]
  82. Now you can continue with
  83. link:VaadinOnGrailsDatabaseAccess.asciidoc[Vaadin
  84. on Grails - Database access]