如何使用 Maven 在 Vaadin 7 中仅编译必要的小部件?

2023-11-26

我是 Vaadin 框架的新手,我看起来非常有趣,使用 eclipse 和 Maven 来开发和构建我的应用程序,我发现很烦人,每次我进行 mvn clean install 时都会花费很长时间来构建应用程序,我发现这是因为它编译了整套小部件。

即使我只在布局中使用按钮,构建应用程序也会花费很多时间。

我在互联网和两本书上研究了一段时间,但找不到足够的信息来说明如何使其仅编译我正在使用的组件而不是整个集合。

我使用 Maven 原型创建了该项目:

mvn archetype:generate -DarchetypeGroupId=com.vaadin -DarchetypeArtifactId=vaadin-archetype-application -DarchetypeVersion=7.1.9

我确信每次构建战争时都会编译小部件集,当我执行 mvn clean 时,它会删除目录: /src/main/webapp/VAADIN/widgetsets 和 /src/main/webapp/VAADIN/gwt-unitCache

当我运行 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] ------------------------------------------------------------------------

之后,再次生成目录 /src/main/webapp/VAADIN/widgetsets,其中包含以下目录:

WEB-INF             
com.my.example.AppWidgetSet

它还生成 /src/main/webapp/VAADIN/gwt-unitCache


您需要自定义小部件集吗?如果您没有使用任何小部件插件,并且由于您是 Vaadin 的新手,我假设您还没有创建自己的小部件(?),您可以简单地使用 Vaadin 提供的预编译小部件集。为此,请从项目中删除任何 xxx.gwt.xml 文件,并将 web.xml 中对其的引用替换为 com.vaadin.DefaultWidgetset。

web.xml:

<init-param>
    <name>widgetset</name>
    <value>com.vaadin.DefaultWidgetSet</value>
</init-param>

pom.xml:

<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin-client-compiled</artifactId>
    <version>7.1.9</version>    <!-- or whatever version you're using -->
</dependency>

如果您确实需要一个自定义小部件集(如果您现在不需要,很可能您以后还需要一个),请帮自己一个忙,将其放入一个单独的项目中。根据我的经验,小部件集很少发生变化,那么为什么要将它包含在不断变化的项目中呢?上面提到的默认小部件集由 Vaadin 提供,是构建小部件集的完美蓝图。只需构建您自己的,并从 vaadin-client-compiled.jar 复制其结构。你可以使用你最喜欢的 Maven 构建助手,我的是汇编。只需创建一个 Maven 项目,设置 pom.xml,添加 xxx.gwt.xml 并确保 web.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>

程序集.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:

<?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 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>

项目结构:

|   pom.xml
|
\---src
    +---main
    |   +---java
    |   |   \---com
    |   |       \---company
    |   |           \---mywidgetset
    |   |                   App.java
    |   |                   MyWidgetset.gwt.xml
    |   |
    |   +---resources
    |   |       assembly.xml
    |   |
    |   \---webapp
    |       \---WEB-INF
    |               web.xml
    |
    \---test
        \---java

构建它,使用该 jar 作为项目中的依赖项,然后就完成了。这将永久地让您摆脱 GWT 称之为“小部件集编译”的巨大痛苦。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Maven 在 Vaadin 7 中仅编译必要的小部件? 的相关文章

随机推荐

  • 如何从 sklearn 反转标签编码器以获取多列?

    我想在多列上使用 LabelEncoder 的 inverse transform 函数 这是我在数据帧上应用 LabelEncoder 时用于多个列的代码 class MultiColumnLabelEncoder def init se
  • matplotlib 3d 表面上的连续阴影

    在 matplotlib 3D 图中 我可以设置行 列数来确定表面上可见的面总数 s ax plot surface x y z color gray shade True rstride 1 cstride 1 其中 rstride 和
  • 使用 ORDER BY 子句的替代结果

    CREATE TABLE TEST customername varchar 50 INSERT INTO TEST VALUES CUSTOMER 1 INSERT INTO TEST VALUES CUSTOMER 1 INSERT I
  • 如何在 jsoup 中获取元素的第一级子元素

    在jsoup中Element children 返回 Element 的所有子元素 后代 但是 我想要元素的第一级子级 直接子级 我可以使用哪种方法 Element children 仅返回直接子元素 既然你把他们绑在树上 他们也会有孩子
  • 如何创建接受不超过 10 位数字的正则表达式?

    如何创建接受不超过 10 位数字的正则表达式 thanks 既然你问了 如何 我将尝试逐步解释 因为您没有指定您正在使用哪种正则表达式风格 所以我将在PCRE and 两个 POSIX 正则表达式变体 For simple在这种情况下 您应
  • 使用 iPhone 音频适配器传输数据

    我刚刚开始在一家生物医学公司工作 我们需要将我们正在制造的设备中的数据传输到 iPhone 显然 使用 iPhone 程序就足够了 但对于原型设计和更简单的解决方案 我想知道我们是否可以使用现有的蓝牙音频发射器 例如 http www bu
  • python高效子字符串搜索[重复]

    这个问题在这里已经有答案了 可能的重复 string find 在 CPython 中是如何实现的 我在堆栈溢出中阅读了许多文章 比较了子字符串搜索的性能 例如Python字符串搜索效率 这是搜索子字符串最有效的方法吗 python 中的子
  • RecyclerView:如何创建插入动画效果?

    我有一个ReyclerView与一个LinearLayoutManager and an Adapter
  • 如何将MySQLi结果集加载到二维数组中?

    我的 mysqli 结果集有问题 我有一个包含一堆消息的表 表中的每一行代表一条消息 我有一些列 例如 ID 标题 正文和 公共 公共列包含布尔值 指定消息是向所有人显示还是仅向发布者显示 我有一个页面 我想在其中显示所有公共消息 如果您单
  • 无法将下载的文件存储在相关文件夹中

    我用 python 结合 selenium 编写了一个脚本 用于从网页下载一些文档文件 以 doc 结尾 我不想使用的原因requests or urllib下载文件的模块是因为我当前正在玩的网站没有任何真实的网址连接到每个文件 它们是 J
  • 大图像的语义分割

    我正在处理数量有限的大尺寸图像 每个图像都可以有3072 3072像素 为了使用 FCN 或 U net 训练语义分割模型 我构建了一个大样本的训练集 每个训练图像是128 128 在预测阶段 我所做的是将大图像切成小块 与训练集相同128
  • Spring:如何使用@Value注释注入内联字符串列表[重复]

    这个问题在这里已经有答案了 如何使用注入字符串值列表 Value注解 我正在使用 Spring 4 1 2 我试过了 Value value top person organizationalPerson user private List
  • 从另一个 Activity 导航回来时,Android Activity onCreate 被调用两次

    我有一个应用程序 可以在用户在 webview 活动上使用 OAuth 进行身份验证后生成音乐 看起来像这样 主要播放器活动 OAuth 活动 返回主要播放器活动 但是 当从 OAuth 活动中调用 onCreate 方法时 会调用两次 导
  • 如何通过Delphi 7上传文件到dropbox?

    我尝试将文件上传到保管箱 我使用 dropbox apihttps www dropbox com developers reference api files POST procedure TDropbox Upload2 const U
  • 读/写 QObject

    I think我可以写一个QObject像这样利用Q PROPERTYs QDataStream operator lt lt QDataStream ds const Object obj for int i 0 i
  • ASP.NET 应用程序保持运行时浏览器超时

    我遇到了一种情况 ASP NET 需要很长时间才能生成网页回复 超过 2 小时 这是由于代码隐藏运行了一段时间 非常长 缓慢的循环 浏览器 IE 和 Firefox 停止等待回复 大约一个小时后 并给出一般的无法显示网页错误 类似于您尝试导
  • 使用 boost::random 作为 std::random_shuffle 的 RNG

    我有一个程序 使用来自 boost random 的 mt19937 随机数生成器 我需要进行 random shuffle 并希望为此生成的随机数来自此共享状态 以便它们可以相对于梅森扭曲器先前生成的数字具有确定性 我尝试过这样的事情 v
  • 不先查询就更新记录?

    假设我查询数据库并加载项目列表 然后 我在详细视图表单中打开其中一个项目 而不是从数据库中重新查询该项目 而是从列表中的数据源创建该项目的实例 有没有办法可以更新数据库记录而不获取单个项目的记录 这是我现在的做法示例 dataItem it
  • jquery 在 contenteditable div 中设置光标位置

    问题的旧版本如下 经过更多研究后 我决定重新表述这个问题 和以前一样 问题是 我需要聚焦一个 contenteditable div 而不突出显示文本 在 Chrome 中直接聚焦突出显示文本 我意识到人们通过重置文本区域中的插入符位置来解
  • 如何使用 Maven 在 Vaadin 7 中仅编译必要的小部件?

    我是 Vaadin 框架的新手 我看起来非常有趣 使用 eclipse 和 Maven 来开发和构建我的应用程序 我发现很烦人 每次我进行 mvn clean install 时都会花费很长时间来构建应用程序 我发现这是因为它编译了整套小部