0

我创建了简单的 vaadin 应用程序并尝试创建我的 vaadin 小部件模块。文件小部件结构如下:

  • 客户
    • 测试连接器
    • 测试小部件
  • 测试
  • 小部件集.gwt.xml
  • MyUI //vaadin UI

此文件的内容如下:

1) 测试连接器

package test.client;

import test.Test;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.communication.RpcProxy;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.ui.Connect;

@Connect(Test.class)
public class TestConnector extends AbstractComponentConnector {
    private final TestServerRpc serverRpc = RpcProxy.create(TestServerRpc.class, this);

    public TestConnector() {
        registerRpc(TestClientRpc.class, new TestClientRpc() {
        });
    }

    @Override
    protected Widget createWidget() {
        return GWT.create(TestWidget.class);
    }

    @Override
    public TestWidget getWidget() {
        return (TestWidget) super.getWidget();
    }

    @Override
    public TestState getState() {
        return (TestState) super.getState();
    }
}

2) 测试小部件

package test.client;

import com.google.gwt.user.client.ui.Label;

public class TestWidget extends Label {

    public static final String CLASSNAME = "mycomponent";

    public TestWidget() {
        setText("This is MyComponent");
        setStyleName(CLASSNAME);
    }
}

3) 测试

package test;

import test.client.TestClientRpc;
import test.client.TestServerRpc;
import test.client.TestState;
import com.vaadin.ui.AbstractComponent;

public class Test extends AbstractComponent {
    public Test() {
        registerRpc(new TestServerRpc() {
            private TestClientRpc getClientRpc() {
                return getRpcProxy(TestClientRpc.class);
            }
        });
    }

    @Override
    protected TestState getState() {
        return (TestState) super.getState();
    }
}

4) WidgetSet.gwt.xml

<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.0//EN"
        "http://gwtproject.org/doctype/2.5.0/gwt-module.dtd">
<module>
    <inherits name="com.vaadin.DefaultWidgetSet"/>
</module>

5) 我的用户界面

package test;

import javax.servlet.annotation.WebServlet;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;


@Theme("mytheme")
public class MyUI extends UI {

    @Override
    protected void init(VaadinRequest vaadinRequest) {
        final VerticalLayout layout = new VerticalLayout();

        Test mywidget = new Test();
        layout.addComponents(mywidget);

        setContent(layout);
    }

    @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false, widgetset = "Test")
    public static class MyUIServlet extends VaadinServlet {
    }
}

当我尝试编译它时,我看到:

    [INFO] --- vaadin-maven-plugin:8.0.5:update-theme (default) @ tests ---
    [INFO] Updating theme VAADIN\themes\mytheme
    [INFO] Widgetsets found from classpath:
    [INFO]  test.WidgetSet in file:/C:/Users/Alexey/IdeaProjects/tests/src/main/java
    [INFO]  com.vaadin.DefaultWidgetSet in jar:file:C:/Users/Alexey/.m2/repository/com/vaadin/vaadin-client/7.1-SNAPSHOT/vaadin-client-7.1-SNAPSHOT.jar!/
    [INFO] Addon styles found from classpath:
    [INFO]
    [INFO] Search took 32ms
    [INFO] Theme "VAADIN\themes\mytheme" updated
    [INFO]
    [INFO] --- vaadin-maven-plugin:8.0.5:update-widgetset (default) @ tests ---
    [INFO] auto discovered modules [test.WidgetSet]
    [INFO] Updating widgetset test.WidgetSet
    [INFO] Adding resource directory to command classpath: C:\Users\Alexey\IdeaProjects\tests\src\main\resources
    [INFO] Using com.vaadin:vaadin-client-compiler version 8.0.5
    [INFO] Widgetsets found from classpath:
    [INFO]  test.WidgetSet in file:/C:/Users/Alexey/IdeaProjects/tests/src/main/java
    [INFO]  com.vaadin.DefaultWidgetSet in jar:file:C:/Users/Alexey/.m2/repository/com/vaadin/vaadin-client/8.0.5/vaadin-client-8.0.5.jar!/
    [INFO] Addon styles found from classpath:
    [INFO]
    [INFO] Search took 40ms
    [INFO]
    [INFO] --- vaadin-maven-plugin:8.0.5:compile-theme (default) @ tests ---
    [INFO] Updating theme VAADIN\themes\mytheme
    [INFO] Theme "VAADIN\themes\mytheme" compiled
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ tests ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ tests ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 7 source files to C:\Users\Alexey\IdeaProjects\tests\target\classes
    [INFO] -------------------------------------------------------------
    [ERROR] COMPILATION ERROR :
    [INFO] -------------------------------------------------------------
    [ERROR] /C:/Users/Alexey/IdeaProjects/tests/src/main/java/test/client/TestConnector.java:[14,8] cannot access com.google.gwt.event.shared.EventHandler
class file for com.google.gwt.event.shared.EventHandler not found
    [ERROR] /C:/Users/Alexey/IdeaProjects/tests/src/main/java/test/client/TestWidget.java:[8,8] cannot access com.google.gwt.event.shared.HasHandlers
class file for com.google.gwt.event.shared.HasHandlers not found
    [INFO] 2 errors
    [INFO] -------------------------------------------------------------
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE

我不明白这个错误的原因,也不知道如何解决。为什么我的程序中需要 com.google.gwt.event.shared.EventHandler 和 com.google.gwt.event.shared.HasHandlers?

pom文件:

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <groupId>test</groupId>
    <artifactId>tests</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>tests</name>

    <prerequisites>
        <maven>3</maven>
    </prerequisites>

    <properties>
        <vaadin.version>8.0.5</vaadin.version>
        <vaadin.plugin.version>8.0.5</vaadin.plugin.version>
        <jetty.plugin.version>9.3.9.v20160517</jetty.plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <!-- If there are no local customisations, this can also be "fetch" or "cdn" -->
        <vaadin.widgetset.mode>local</vaadin.widgetset.mode>
    </properties>

    <repositories>
        <repository>
            <id>vaadin-addons</id>
            <url>http://maven.vaadin.com/vaadin-addons</url>
        </repository>
    </repositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>${vaadin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-server</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-push</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-client-compiled</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-themes</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-client</artifactId>
            <version>7.1-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <!-- Exclude an unnecessary file generated by the GWT compiler. -->
                    <packagingExcludes>WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-maven-plugin</artifactId>
                <version>${vaadin.plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>update-theme</goal>
                            <goal>update-widgetset</goal>
                            <goal>compile</goal>
                            <!-- Comment out compile-theme goal to use on-the-fly theme compilation -->
                            <goal>compile-theme</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
                <!-- Clean up also any pre-compiled themes -->
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>src/main/webapp/VAADIN/themes</directory>
                            <includes>
                                <include>**/styles.css</include>
                                <include>**/styles.scss.cache</include>
                            </includes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>

            <!-- The Jetty plugin allows us to easily test the development build by
                running jetty:run on the command line. -->
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.plugin.version}</version>
                <configuration>
                    <scanIntervalSeconds>2</scanIntervalSeconds>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- Vaadin pre-release repositories -->
            <id>vaadin-prerelease</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>

            <repositories>
                <repository>
                    <id>vaadin-prereleases</id>
                    <url>http://maven.vaadin.com/vaadin-prereleases</url>
                </repository>
                <repository>
                    <id>vaadin-snapshots</id>
                    <url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>vaadin-prereleases</id>
                    <url>http://maven.vaadin.com/vaadin-prereleases</url>
                </pluginRepository>
                <pluginRepository>
                    <id>vaadin-snapshots</id>
                    <url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>

</project>
4

1 回答 1

0

看起来您没有在您的依赖项之一中使用 8.0.5 vaadin 版本,请将其更改7.1-SNAPSHOT${vaadin.version}

    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-client</artifactId>
        <version>${vaadin.version}</version>
    </dependency>

您可能可以删除以下依赖项,因为它与上述依赖项相同:

    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-client-compiled</artifactId>
    </dependency>
于 2017-05-01T15:46:10.280 回答