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

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