How can I compile only necessary widgets in Vaadin 7 with Maven?

后端 未结 4 988
慢半拍i
慢半拍i 2020-12-24 08:27

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 mv

相关标签:
4条回答
  • 2020-12-24 09:07

    To reduce the compile time of the widgetset you could and following to the .gwt.xml file and uncomment the set-property tag.

    <!-- 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.

    0 讨论(0)
  • 2020-12-24 09:14

    If you tired with constant compiling/recompiling widgetsets, I suggest you to use "CDN Viritin Magic"

    Benefits:

    1. No @Widgetset
    2. no need in maven-vaadin-plugin
    3. Decreases compilation time in N-times.

    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 :

    @Bean
    public in.virit.WidgetSet viritinCdnInitializer() {
        return new in.virit.WidgetSet();
    }
    

    Note 2: It's OK to use alongside with spring-boot-maven-plugin

    0 讨论(0)
  • 2020-12-24 09:18

    Just dont compile any widget, use the default one; for that you must set the following files: web.xml:

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

    Or in the UI implementation for your project:

    /**
     * Initial view in Vaadin
     */
    @Theme("valo") 
    @Widgetset("com.vaadin.DefaultWidgetSet")
    public class MainUI extends UI
    {
    

    Finally in the pom.xml include just these dependencies:

        <!-- 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.

    0 讨论(0)
  • 2020-12-24 09:23

    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.

    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>
    

    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.

    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:

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

    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".

    0 讨论(0)
提交回复
热议问题