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

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