Java 如何使用 Maven 在 Vaadin 7 中仅编译必要的小部件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21005268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I compile only necessary widgets in Vaadin 7 with Maven?
提问by raspacorp
I am new to the Vaadin framework which I looks very interesting, using eclipse and maven to develop and build my application I find pretty annoying that every time I do a mvn clean install it will take so long time to build the app, I found that this is because it compiles the whole set of widgets.
我是 Vaadin 框架的新手,我看起来很有趣,使用 eclipse 和 maven 来开发和构建我的应用程序我觉得很烦人,每次我执行 mvn clean install 都需要很长时间来构建应用程序,我发现这是因为它编译了整套小部件。
Even if I am only using a Button in my layout it will take so much on building the app.
即使我只在布局中使用 Button,构建应用程序也需要花费很多时间。
I have researched for some time in the Internet and 2 books but cannot find enough information about how to make it to only compile components that I am using and not the whole set.
我已经在 Internet 和 2 本书中研究了一段时间,但找不到足够的信息来说明如何仅编译我正在使用的组件而不是整个集合。
I created the project by using the maven archetype:
我使用 maven 原型创建了该项目:
mvn archetype:generate -DarchetypeGroupId=com.vaadin -DarchetypeArtifactId=vaadin-archetype-application -DarchetypeVersion=7.1.9
I am sure that the widgetset is being compiled every time I build the war, when I do a mvn clean it removes the directory: /src/main/webapp/VAADIN/widgetsets and /src/main/webapp/VAADIN/gwt-unitCache
我确定每次构建战争时都会编译小部件集,当我执行 mvn clean 时,它会删除目录:/src/main/webapp/VAADIN/widgetsets 和 /src/main/webapp/VAADIN/gwt-unitCache
When I run mvn install the build will last for more than 3 minutes:
当我运行 mvn install 时,构建将持续超过 3 分钟:
...
[INFO] Compiling 6 permutations
[INFO] Compiling permutation 0...
[INFO] Process output
[INFO] Compiling
[INFO] Compiling permutation 1...
[INFO] Process output
[INFO] Compiling
[INFO] Compiling permutation 3...
[INFO] Process output
[INFO] Compiling
[INFO] Compiling permutation 2...
[INFO] Compiling permutation 4...
[INFO] Compiling
[INFO] Compiling permutation 5...
[INFO] Compile of permutations succeeded
[INFO] Linking into /.../example/src/main/webapp/VAADIN/widgetsets/com.my.example.AppWidgetSet; Writing extras to /.../example/target/extra/com.my.example.AppWidgetSet
[INFO] Link succeeded
[INFO] Compilation succeeded -- 167.103s
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ ade ---
[INFO] Packaging webapp
[INFO] Assembling webapp [example] in [/.../example/target/example-0.1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/.../example/src/main/webapp]
[INFO] Webapp assembled in [562 msecs]
[INFO] Building war: /.../example/target/example-0.1.0-SNAPSHOT.war
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ ade ---
[INFO] Installing /.../example/target/example-0.1.0-SNAPSHOT.war to /.../example/0.1.0-SNAPSHOT/example-0.1.0-SNAPSHOT.war
[INFO] Installing /.../example/pom.xml to /.../example/0.1.0-SNAPSHOT/example-0.1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3:03.768s
[INFO] Finished at: Fri Jan 10 00:10:45 EST 2014
[INFO] Final Memory: 16M/81M
[INFO] ------------------------------------------------------------------------
After this the directory /src/main/webapp/VAADIN/widgetsets is generated again containing the following directories:
在此之后,目录 /src/main/webapp/VAADIN/widgetsets 再次生成,其中包含以下目录:
WEB-INF
com.my.example.AppWidgetSet
It also generates /src/main/webapp/VAADIN/gwt-unitCache
它还生成 /src/main/webapp/VAADIN/gwt-unitCache
采纳答案by atmo
Do you need a custom widgetset? If you're not using any widget addons, and since your're new to Vaadin I am assuming that you did not create your own widgets yet(?), you can simply use the precompiled widgetset provided by Vaadin. To do this, remove any xxx.gwt.xml file from your project, and replace the reference to it in web.xml with com.vaadin.DefaultWidgetset.
您需要自定义小部件集吗?如果您没有使用任何小部件插件,并且由于您是 Vaadin 的新手,我假设您还没有创建自己的小部件(?),您可以简单地使用 Vaadin 提供的预编译小部件集。为此,请从您的项目中删除任何 xxx.gwt.xml 文件,并将 web.xml 中对其的引用替换为 com.vaadin.DefaultWidgetset。
web.xml:
网页.xml:
<init-param>
<name>widgetset</name>
<value>com.vaadin.DefaultWidgetSet</value>
</init-param>
pom.xml:
pom.xml:
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiled</artifactId>
<version>7.1.9</version> <!-- or whatever version you're using -->
</dependency>
If you do need a custom widgetset (and if you don't now, chances are that you will need one further down the road), do yourself a favor and put it in a separate project. In my experience, a widgetset very seldom changes, so why include it in a project that constantly changes. The default widgetset mentioned above, provided by Vaadin, is the prefect blueprint for building one. Just build your own, and copy its structure from vaadin-client-compiled.jar. You can use your favourite maven build helper for that, mine is assembly. Just create a maven project, setup pom.xml, add a xxx.gwt.xml and make sure web.xml contains a reference to it. My own setup looks something like what you see below.
如果您确实需要一个自定义小部件集(如果您现在不需要,很可能以后您还需要一个),帮自己一个忙并将其放在一个单独的项目中。根据我的经验,widgetset 很少改变,那么为什么要把它包含在一个不断变化的项目中。上面提到的默认小部件集由 Vaadin 提供,是构建它的完美蓝图。只需构建您自己的,并从 vaadin-client-compiled.jar 复制其结构。你可以使用你最喜欢的 Maven 构建助手,我的是组装。只需创建一个 maven 项目,设置 pom.xml,添加一个 xxx.gwt.xml 并确保 web.xml 包含对它的引用。我自己的设置看起来像你在下面看到的。
pom.xml:
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>MyWidgetset</name>
<groupId>com.company</groupId>
<artifactId>mywidgetset</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vaadin.version>7.1.9</vaadin.version>
<vaadin.plugin.version>7.1.9</vaadin.plugin.version>
</properties>
<dependencies>
<!-- vaadin -->
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client</artifactId>
<version>${vaadin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiler</artifactId>
<version>${vaadin.version}</version>
<scope>provided</scope>
</dependency>
<!-- custom widgets (NOTE: addons without a widget do not belong here) -->
<dependency>
<groupId>org.vaadin.addons</groupId>
<artifactId>filteringtable</artifactId>
<version>0.9.3.v7</version>
</dependency>
<dependency>
<groupId>org.vaadin.addons</groupId>
<artifactId>popupbutton</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- vaadin update widgetset -->
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.plugin.version}</version>
<configuration>
<extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
<webappDirectory>${basedir}/target/VAADIN/widgetsets</webappDirectory>
<hostedWebapp>${basedir}/target/VAADIN/widgetsets</hostedWebapp>
<force>false</force>
<strict>true</strict>
<noServer>true</noServer>
<compileReport>true</compileReport>
<style>OBF</style>
<runTarget>http://localhost:8080/</runTarget>
</configuration>
<executions>
<execution>
<goals>
<goal>resources</goal>
<goal>update-widgetset</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/resources/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>
</project>
assembly.xml:
程序集.xml:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>build-my-widgetset-jar</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${basedir}/target/VAADIN/widgetsets</directory>
<outputDirectory>/VAADIN/widgetsets</outputDirectory>
<excludes>
<exclude>WEB-INF/</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
MyWidgetset.gwt.xml:
我的Widgetset.gwt.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC
"-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN"
"http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.vaadin.DefaultWidgetSet" />
<inherits name="org.tepi.filtertable.gwt.FilterTableWidgetset" />
<inherits name="org.vaadin.hene.popupbutton.widgetset.PopupbuttonWidgetset" />
</module>
web.xml:
网页.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>MyWidgetset</display-name>
<servlet>
<servlet-name>MyWidgetset</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
<init-param>
<param-name>ui</param-name>
<param-value>com.company.mywidgetset.App</param-value> <!-- use it for testing the widgetset-->
</init-param>
<init-param>
<param-name>widgetset</param-name>
<param-value>com.company.mywidgetset.MyWidgetset</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyWidgetset</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
project structure:
项目结构:
| pom.xml
|
\---src
+---main
| +---java
| | \---com
| | \---company
| | \---mywidgetset
| | App.java
| | MyWidgetset.gwt.xml
| |
| +---resources
| | assembly.xml
| |
| \---webapp
| \---WEB-INF
| web.xml
|
\---test
\---java
Build it, use the jar as a dependency in your project, and you're done. This will permanently release you from the big pain-in-the-butt that GWT calls "widgetset compilation".
构建它,将 jar 用作项目中的依赖项,就大功告成了。这将使您永远摆脱 GWT 称为“widgetset 编译”的巨大痛苦。
回答by Supun Sameera
To reduce the compile time of the widgetset you could and following to the .gwt.xml file and uncomment the set-property tag.
要减少小部件集的编译时间,您可以遵循 .gwt.xml 文件并取消注释 set-property 标记。
<!-- Uncomment the following to compile the widgetset for one browser only.
This can reduce the GWT compilation time significantly when debugging. The
line should be commented out before deployment to production environments.
Multiple browsers can be specified for GWT 1.7 as a comma separated list.
The supported user agents at the moment of writing were: ie6,ie8,gecko,gecko1_8,safari,opera
The value gecko1_8 is used for Firefox 3 and later and safari is used for
webkit based browsers including Google Chrome. -->
<!-- <set-property name="user.agent" value="gecko1_8"/> -->
to create a new vaadin-maven project, you could try use the vaadin 7 plugin new project wizard which will create a new project with ivy dependency management, after creating the project, right click on the project and remove ivy dependency management, and then right click --> configure--> convert it to maven project will add maven dependency management to the project.
要创建一个新的 vaadin-maven 项目,您可以尝试使用 vaadin 7 plugin new project Wizard 它将创建一个带有 ivy 依赖管理的新项目,创建项目后,右键单击该项目并删除 ivy 依赖管理,然后右键点击-->configure-->convert it to maven project会为项目添加maven依赖管理。
回答by EliuX
Just dont compile any widget, use the default one; for that you must set the following files: web.xml:
只是不要编译任何小部件,使用默认的;为此,您必须设置以下文件:web.xml:
<init-param>
<name>widgetset</name>
<value>com.vaadin.DefaultWidgetSet</value>
</init-param>
Or in the UIimplementation for your project:
或者在您的项目的UI实现中:
/**
* Initial view in Vaadin
*/
@Theme("valo")
@Widgetset("com.vaadin.DefaultWidgetSet")
public class MainUI extends UI
{
Finally in the pom.xmlinclude just these dependencies:
最后在pom.xml 中只包含这些依赖项:
<!-- Vaadin dependencies -->
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-server</artifactId>
<version>${vaadin.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiled</artifactId>
<version>${vaadin.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-themes</artifactId>
<version>${vaadin.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
Nothing else. I solved with these, i hope you too.
没有其他的。我用这些解决了,我希望你也是。
回答by Reborn
If you tired with constant compiling/recompiling widgetsets, I suggest you to use "CDN Viritin Magic"
如果您厌倦了不断编译/重新编译小部件集,我建议您使用“ CDN Viritin Magic”
Benefits:
好处:
- No
@Widgetset
- no need in
maven-vaadin-plugin
- Decreases compilation time in N-times.
- 不
@Widgetset
- 不需要在
maven-vaadin-plugin
- 减少 N 次编译时间。
Note 1 (for Vaadin Spring Boot users):
After successful tutorial walkthrough(do not run mvn clean install
yet!)
You have to define one more thing in YourAppNameApplication
class :
注意 1(适用于 Vaadin Spring Boot 用户):
在成功的教程演练之后(不要运行mvn clean install
!)
你必须在YourAppNameApplication
课堂上再定义一件事情:
@Bean
public in.virit.WidgetSet viritinCdnInitializer() {
return new in.virit.WidgetSet();
}
Note 2:It's OK to use alongside with spring-boot-maven-plugin
注2:可以和with一起使用spring-boot-maven-plugin