简体   繁体   English

Vaadin应用程序可从命令行运行,但不能在IntelliJ中运行

[英]Vaadin application working from command line but not in IntelliJ

Utilities: IntelliJ, Glassfish server, Vaadin API 实用工具:IntelliJ,Glassfish服务器,Vaadin API

EDIT: I should mention that this is my first time using Vaadin 编辑:我应该提到这是我第一次使用Vaadin

I have a simple Vaadin application that I'm trying to launch as a test. 我有一个简单的Vaadin应用程序,试图将其作为测试启动。 If I run it on the command line (with Maven) and launch it from the Glassfish Applications panel in the admin console, it works perfectly. 如果我在命令行(使用Maven)上运行它,并从管理控制台的Glassfish应用程序面板中启动它,则它可以完美运行。 When I try to use the same code in IntelliJ, I get a 404 error. 当我尝试在IntelliJ中使用相同的代码时,出现404错误。 I want to use IntelliJ for debugging purposes, so it's important that I get it to work from there as well. 我想将IntelliJ用于调试目的,因此从那里开始工作也很重要。 Here is the code I am using: 这是我正在使用的代码:

@Title("test")
@Theme("valo")
public class MyVaadinApplication extends UI {
    private String user;
    private String pwd;

    @WebServlet(value = "/*", asyncSupported = false)
    @VaadinServletConfiguration(productionMode = false, ui = MyVaadinApplication.class)
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {

        FormLayout form = new FormLayout();
        setContent(form);

        TextField nameField = new TextField("Name:");
        PasswordField passField = new PasswordField("Password:");
        Button button = new Button("Login");

        form.addComponent(nameField);
        form.addComponent(passField);
        form.addComponent(button);

        button.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                user = nameField.getValue();
                pwd = passField.getValue();
            }
        });

    }
}

Here is the web.xml (it's pretty empty and irrelevant). 这是web.xml(非常空白且无关紧要)。 From my understanding, if you use the @WebServlet and @VaadinServletConfiguration annotations, you do not need to specify any mappings/servlets in the web.xml file. 据我了解,如果使用@WebServlet和@VaadinServletConfiguration批注,则无需在web.xml文件中指定任何映射/ servlet。 Somebody please correct me if I'm wrong. 如果我错了,请有人纠正我。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>test</display-name>

<security-role>
    <role-name>admin</role-name>
</security-role>

<security-role>
    <role-name>user</role-name>
</security-role>

And finally my Maven pom.xml: 最后是我的Maven pom.xml:

<?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>gov.bnl.cad</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<properties>
    <vaadin.version>7.4.2</vaadin.version>
    <vaadin.plugin.version>${vaadin.version}</vaadin.plugin.version>
    <jetty.plugin.version>9.2.3.v20140905</jetty.plugin.version>
    <project.source.version>1.8</project.source.version>
    <project.target.version>1.8</project.target.version>
    <project.encoding>UTF-8</project.encoding>
</properties>
<distributionManagement>
    <repository>
        <id>CAD Repo</id>
        <url>file:///usr/common/jar/cad-repo</url>
    </repository>
    <site>
        <id>${project.artifactId}</id>
        <url>/usr/common/jar/cad-repo/${project.artifactId}</url>
    </site>
</distributionManagement>
<repositories>
    <repository>
        <id>CAD Repo</id>
        <url>file:///usr/common/jar/cad-repo/</url>
    </repository>
    <repository>
        <id>vaadin-addons</id>
        <url>http://maven.vaadin.com/vaadin-addons</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>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <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>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-themes</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-push</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>3.0-alpha-1</version>
    </dependency>
    <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-compiled</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-client-compiler</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>gov.bnl.cad</groupId>
        <artifactId>pageParser</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>gov.bnl.cad</groupId>
        <artifactId>rcs-cad</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>


<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.4.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <classpathScope>compile</classpathScope>
                            <mainClass>com.vaadin.sass.SassCompiler</mainClass>
                            <arguments>
                                <argument>src/main/webapp/VAADIN/themes/dashbuilder/styles.scss</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <encoding>${project.encoding}</encoding>
                    <source>${project.source.version}</source>
                    <target>${project.target.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <encoding>${project.encoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <!-- Exclude some unnecessary files generated by the GWT compiler. -->
                    <packagingExcludes>WEB-INF/classes/VAADIN/gwt-unitCache/**,
                        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>
                <configuration>
                    <extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
                    <webappDirectory>${basedir}/target/classes/VAADIN/widgetsets</webappDirectory>
                    <draftCompile>false</draftCompile>
                    <compileReport>false</compileReport>
                    <style>OBF</style>
                    <strict>true</strict>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>clean</goal>
                            <goal>resources</goal>
                            <goal>update-theme</goal>
                            <goal>update-widgetset</goal>
                            <goal>compile-theme</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.4</version>
            </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>
    </pluginManagement>
</build>

Any help is greatly appreciated. 任何帮助是极大的赞赏。 Thank you! 谢谢!

With Servlet 3+ you don't need to use web.xml at all, given annotations are provided in your code. 使用Servlet 3+,您完全不需要使用web.xml,因为在代码中提供了给定的注释。 So you can just delete that file if you want. 因此,您可以根据需要删除该文件。 If you use web.xml it will override your annotated settings. 如果您使用web.xml,它将覆盖您的注释设置。

So delete your web.xml file and change value = "/*" to urlPatterns = "/*" in @WebServlet annotation then try again. 因此,删除您的web.xml文件,然后在@WebServlet批注中将value = "/*"更改为urlPatterns = "/*" ,然后重试。

If it still doesn't work, you need to check your IntelliJ run configurations explicitly. 如果仍然不起作用,则需要显式检查IntelliJ运行配置。 Your server might not be configured properly in the IDE. 您的服务器可能未在IDE中正确配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM