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.

clientside-compiling.asciidoc 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. ---
  2. title: Compiling a Client-Side Module
  3. order: 4
  4. layout: page
  5. ---
  6. [[clientside.compiling]]
  7. = Compiling a Client-Side Module
  8. A client-side module, either a Vaadin widget set or a pure client-side module, needs to be compiled to JavaScript using the Vaadin Client Compiler.
  9. Widget set compilation is most often needed when using add-ons.
  10. In that case, the widget sets from different add-ons are compiled into an _application widget set_, as described in <<../addons/addons-overview.asciidoc#addons.overview, "Using Vaadin Add-ons">>.
  11. When doing client-side development, you need to compile the widget set every time you modify the client-side code.
  12. [[clientside.compiling.overview]]
  13. == Vaadin Compiler Overview
  14. The Vaadin Client Compiler compiles Java to JavaScript.
  15. It is provided as the executable [filename]#vaadin-client-compiler# JAR.
  16. // You can run it with the [literal]#++-jar++# parameter for the Java runtime.
  17. It requires the [filename]#vaadin-client# JAR, which contains the [classname]#DefaultWidgetSet#, Vaadin client-side framework.
  18. The compiler compiles a _client module_, which can either be a pure client-side module or a Vaadin widget set, that is, the Vaadin Client-Side Engine that includes the widgets used in the application.
  19. The client module is defined with a module descriptor, which was described in <<clientside-module#clientside.module, "Client-Side Module Descriptor">>.
  20. The module descriptor for application widget sets is automatically generated.
  21. While you can compile client modules individually, in Vaadin applications you normally combine them in one application widget set.
  22. The application widget set includes any add-on and custom widgets.
  23. The compiler scans the class path for any widget sets to include in the application widget set.
  24. === Compilation Result
  25. The compiler writes the compilation result to a target folder that will include the compiled JavaScript with any static resources included in the module.
  26. [[clientside.compiling.maven]]
  27. == Compiling in Maven Projects
  28. The Vaadin Maven Plugin, which is enabled in all Vaadin archetypes, makes Maven to automatically compile the widget set when necessary.
  29. ifdef::web[]
  30. === Plugin Configuration
  31. [source,xml]
  32. ----
  33. <plugin>
  34. <groupId>com.vaadin</groupId>
  35. <artifactId>vaadin-maven-plugin</artifactId>
  36. <version>${vaadin.plugin.version}</version>
  37. <configuration>
  38. <extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
  39. <webappDirectory>${basedir}/target/classes/VAADIN/widgetsets</webappDirectory>
  40. <draftCompile>false</draftCompile>
  41. <compileReport>false</compileReport>
  42. <style>OBF</style>
  43. <strict>true</strict>
  44. </configuration>
  45. <executions>
  46. <execution>
  47. <goals>
  48. <goal>update-theme</goal>
  49. <goal>update-widgetset</goal>
  50. <goal>compile</goal>
  51. <goal>compile-theme</goal>
  52. </goals>
  53. </execution>
  54. </executions>
  55. </plugin>
  56. ----
  57. endif::web[]
  58. [[clientside.compiling.maven.modes]]
  59. === Compilation Modes
  60. The Vaadin Maven Plugin can compile widget sets either locally or online by using a cloud service.
  61. The online compilation requires that all the widget sets are available in certain public Maven repositories.
  62. As this is not the case when developing custom widgets, you must use the `local` mode.
  63. Local compilation is the default mode, so you only need to enable it if you have changed the mode to use the online service.
  64. See <<../addons/addons-maven#addons.maven.modes, "Widget Set Modes">> for more information.
  65. [[clientside.compiling.maven.compiling]]
  66. === Compiling
  67. You can explicitly compile the widget set with the [literal]#vaadin:compile# goal.
  68. On command-line:
  69. [subs="normal"]
  70. ----
  71. [prompt]#$# [command]#mvn# [parameter]#vaadin:compile#
  72. ----
  73. If there is no widget set defined, but you have add-on dependencies that need a
  74. custom widget set, the Vaadin Maven plugin will automatically generate a widget set definition for you.
  75. [[clientside.compiling.eclipse]]
  76. == Compiling in Eclipse
  77. When you have the Vaadin Plugin installed in Eclipse, you can simply click the *Compile Vaadin Widgetset* button in the toolbar.
  78. .Widget set compilation button in Eclipse
  79. image::img/widgetset-compiling-toolbar.png[width=50%, scaledwidth=60%]
  80. It will compile the widget set it finds from the project.
  81. If the project has multiple widget sets, such as one for custom widgets and another one for the project, you need to select the module descriptor of the widget set to compile before clicking the button.
  82. Compiling with the Vaadin Plugin for Eclipse currently requires that the module descriptor has suffix [filename]#Widgetset.gwt.xml#, although you can use it to compile also other client-side modules than widget sets.
  83. The result is written under [filename]#WebContent/VAADIN/widgetsets# folder.
  84. ifdef::web[]
  85. [[clientside.compiling.ant]]
  86. == Compiling with Ant
  87. Consider the following configuration:
  88. [source, xml, subs="normal"]
  89. ----
  90. <target name="configure">
  91. <!-- Where project source files are located -->
  92. <property name="sources" value="[replaceable]#src#" />
  93. <!-- Path to root of web application folder -->
  94. <property name="webroot" value="[replaceable]#WebContent#" />
  95. <!-- Compilation work directory -->
  96. <property name="workdir" value="[replaceable]#build/work#"/>
  97. </target>
  98. ----
  99. The script assumes the Eclipse project layout with [filename]#WebContent# folder.
  100. The `compile-widgetset` target invokes the Vaadin Compiler to compile the widget set.
  101. The class path includes source folder in case there are custom widgets, compiled server-side classes, and the dependencies resolved with Ivy.
  102. [source, xml]
  103. ----
  104. <target name="compile-widgetset" depends="init,resolve">
  105. <java classname="com.google.gwt.dev.Compiler"
  106. failonerror="yes" fork="yes">
  107. <arg value="-war" />
  108. <arg value="${webroot}/VAADIN/widgetsets" />
  109. <arg value="${widgetset}" />
  110. <arg value="-logLevel"/>
  111. <arg value="INFO"/>
  112. <!-- <arg value="-strict"/> -->
  113. <jvmarg value="-Xmx1024M"/>
  114. <jvmarg value="-Xss512M"/>
  115. <jvmarg value="-Djava.awt.headless=true"/>
  116. <classpath>
  117. <!-- Location of source code -->
  118. <pathelement path="${sources}" />
  119. <!-- Compiled server-side classes -->
  120. <pathelement path="${workdir}/WEB-INF/classes" />
  121. <!-- Dependencies retrieved with Ivy -->
  122. <path refid="ivy.deps.widgetset"/>
  123. </classpath>
  124. <sysproperty key="vFailIfNotSerializable" value="${failifnotserializable}" />
  125. </java>
  126. <!-- Cleanup -->
  127. <delete dir="${webroot}/VAADIN/gwt-unitCache"/>
  128. <delete dir="${webroot}/VAADIN/widgetsets/WEB-INF"/>
  129. </target>
  130. ----
  131. You can copy the example build script to your project and, once configured, run it with Ant.
  132. You may need to do some configuration in the build targets, such as to exclude or include source or target paths.
  133. endif::web[]