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.

ComponentAddonProjectSetupHOWTO.asciidoc 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. ---
  2. title: Component Addon Project Setup HOWTO
  3. order: 77
  4. layout: page
  5. ---
  6. [[component-add-on-project-setup-howto]]
  7. = Component add-on project setup how-to
  8. This how-to walks you through a complete setup for a project for
  9. developing, building and publishing your own Vaadin UI component
  10. add-ons. The goal here is not to teach how to write an add-on, but to
  11. make the process of setting up your project environment as smooth as
  12. possible. I hope this encourages you to try building and publishing your
  13. own add-ons :)
  14. [[goals-for-the-project-environment]]
  15. Goals for the project environment
  16. ---------------------------------
  17. * Fully automated build with Maven
  18. * Allow anyone to re-build your project easily regardless of the IDE:s
  19. * Almost instant save-build-deploy-try cycle
  20. * Simple, but complete, project setup
  21. * Project publishing to GitHub
  22. * Easy publishing of the results to Vaadin Directory
  23. [[install-toolchain]]
  24. Install toolchain
  25. -----------------
  26. If you do not already have the following tools in use, install them:
  27. * Eclipse IDE for Java EE developers from http://www.eclipse.org (Indigo
  28. Service Release 1 was used in this how-to)
  29. * Google Chrome browser from https://www.google.com/chrome/ (other
  30. browsers will do, but Chrome is recommended)
  31. * Eclipse plugins: m4e-wtp, vaadin, egit (optional) and jrebel
  32. (optional) from Marketplace (just select Help->Marketplace... from the
  33. menu)
  34. [[create-a-new-widget-project]]
  35. Create a new widget project
  36. ---------------------------
  37. Start project creation wizard: File -> New -> Other... -> "Maven
  38. Project"
  39. Give a proper name for your project and save it under workspace. For
  40. this example I am building a list widget and name it MyList.
  41. Ensure that your Maven archetype catalogs contain
  42. http://repo1.maven.org/maven2/archetype-catalog.xml as remote catalog
  43. and select it.
  44. Select vaadin-archetype-widget from the list.
  45. Give a proper name for the project. I use "org.vaadin" as group id as it
  46. can be used by anyone who wants to contribute non-commercial widgets to
  47. Vaadin project and name of the widget as artifact id in this case i use
  48. "mylist" as example. For a package name use "org.vaadin.mylist".
  49. Observe that pom.xml shows two errors. This is because m2e does not
  50. directly support gwt and vaadin -plugins. To fix the problem, choose the
  51. problems one by one and choose "ignore" quick fix. Then edit the pom.xml
  52. by changing all `<ignore></ignore>` tags to `<execute></execute>` to get the
  53. plugins to execute. Finally, clear the remaining "project configuration
  54. needs update" error with quickfix (that not surprisingly updates project
  55. configuration). In the end, pom.xml should look like
  56. https://raw.github.com/jojule/MyList/56ac906f9cc6442e0817eb0cc945eee023ff9001/pom.xml[this].
  57. Refactor the name of the component you are building.
  58. * Instead of using `MyComponent` and `VMyComponent`, use your own name. In
  59. this example I use `MyList` and `VMyList`.
  60. * Also change the theme directory name from
  61. `src/main/java/org/vaadin/mylist/gwt/public/mywidget` to
  62. `src/main/java/org/vaadin/mylist/gwt/public/mylist`
  63. * and update the reference in `MyWidgetSet.gwt.xml`.
  64. * Also rename `MyWidgetSet.gwt.xml` to `MyListWidgetSet.gwt.xml`
  65. * and update references in `pom.xml` and `web.xml`.
  66. Test that the project compiles and runs by running (Run -> Run as ... ->
  67. Maven Build...) maven goal "package jetty:run". If everything compiles
  68. fine and Jetty server starts, you can access the application at
  69. http://localhost:8080/mylist/. You should see "It works!" on the web
  70. page. Do not worry that the build takes a lot of time, we'll get back to
  71. it in a minute.
  72. Finally, if you prefer to use Git, create a repository for the project.
  73. You could simply choose "Share Project..." from the Project's Team menu.
  74. Choose "Use or create repository in parent folder" and click "Create
  75. Repository". Then, add project resources to commit. Choose pom.xml and
  76. src directory from Navigator view and select Team -> Add to Index. Then
  77. add the rest of the files (.settings, .project, .classpath and target)
  78. to .gitignore with Team -> Ignore. Finally, just do Team -> Commit.
  79. At this point - or later whenever you are ready for it - you can
  80. publish the project to GitHub. Just go to github.com and create a new
  81. repository. Use MyList as the name for the repository. Then follow the
  82. instructions on the screen. In my case, I executed the following command
  83. line commands: `cd /Users/phoenix/Documents/workspace/mylist; git remote
  84. add origin git@github.com:jojule/MyList.git; git push -u origin master`.
  85. You can see the results
  86. https://github.com/jojule/MyList/tree/56ac906f9cc6442e0817eb0cc945eee023ff9001[at
  87. GitHub].
  88. [[save---build---deploy---try]]
  89. Save - Build - Deploy - Try
  90. ---------------------------
  91. If it takes minutes each time from code change to seeing that change on
  92. the screen, you are not going to get your component ready anytime soon.
  93. To solve the issue, we use two tools: 1) Google GWT Developer Mode and
  94. 2) JRebel. The first one is more important here as the GWT compilation
  95. step is the really slow step, but JRebel also helps as it gives you
  96. instant redeploy for the server-side changes.
  97. To enable JRebel, open project popup menu and choose JRebel -> Generate
  98. rebel.xml in `src/main/java`. Then click "Enable JRebel" on the JRebel tab
  99. for Maven run configuration for "jetty:run". Now when you make any
  100. changes to server-side code - for example to `WidgetTestApplication.java`
  101. - hit save and reload the browser pointing to
  102. http://localhost:8080/mylist/?restartApplication, the changes are
  103. applied immediately. Even better - you can start the project with Debug
  104. As and add break points to the application.
  105. Client-side changes are more tricky as they are compiled from Java to
  106. JavaScript by GWT. To make those changes immediately you, must be
  107. running a GWT Development Mode. This is done by running Maven goal gwt:run
  108. instead of just pointing your web browser to the running application.
  109. Note that must be running both jetty:run and gwt:run concurrently.
  110. gwt:run starts application called "GWT Development Mode". From there you
  111. can launch your browser - or cut-n-paste URL to Chrome - if that is not
  112. your default browser. When the application is started, add
  113. `&restartApplication` parameter to the end of the URL to ensure that the
  114. server-side of the application is reloaded each time you reload the
  115. page. In this case, the full url is
  116. http://127.0.0.1:8080/mylist/?gwt.codesvr=127.0.0.1:9997&restartApplication.
  117. Try making a change to the client-side code (for example `VMyList.java`),
  118. hitting save and reloading the page to see how everything works
  119. together. You can also run gwt:run in Debug As to debug the client-side
  120. code.
  121. Now the "save - build - deploy - try" cycle has been reduced to almost
  122. instant for both client-side as well as server-side changes. Let the
  123. real development begin.
  124. [[developing-a-new-component-for-vaadin]]
  125. Developing a new component for Vaadin
  126. -------------------------------------
  127. Wait for an amazing idea, code like crazy, enjoy and POOOF, there it is
  128. - your own brand new component.
  129. If you need guidance with this,
  130. https://vaadin.com/book/-/page/gwt.html[Book of Vaadin] is a recommended
  131. reading :)
  132. For this example, I implemented a trivial list component. Take a look of
  133. 1.0.0 version
  134. https://github.com/jojule/MyList/tree/496a8bdf629154a4da7b83c4a11979272959aa96[at
  135. GitHub], but do not expect too much :) To try it out just do: `git clone
  136. git@github.com:jojule/MyList.git; mvn package; mvn jetty:run` and point
  137. your web browser to http://localhost:8080/mylist/.
  138. [[packaging-and-submitting-the-widget-to-directory]]
  139. Packaging and submitting the widget to directory
  140. ------------------------------------------------
  141. Set the version number in pom.xml
  142. Run Maven target "package" and you'll have a ready made package at
  143. target/mylist-1.0.0.jar ready for upload to vaadin directory.
  144. Go to https://vaadin.com/directory/my-components, select UI Component and
  145. click upload.
  146. Fill the form, preview and publish.