实用程序:IntelliJ,Glassfish服务器,Vaadin API
编辑:我应该提到这是我第一次使用Vaadin
我有一个简单的Vaadin应用程序,我试图将其作为测试启动。如果我在命令行上运行它(使用Maven)并从管理控制台中的Glassfish Applications面板启动它,它可以完美地运行。当我尝试在IntelliJ中使用相同的代码时,我收到404错误。我想使用IntelliJ进行调试,所以我也可以从那里开始工作。这是我正在使用的代码:
@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();
}
});
}
}
这是web.xml(它非常空且无关紧要)。根据我的理解,如果使用@WebServlet和@VaadinServletConfiguration注释,则无需在web.xml文件中指定任何映射/ servlet。如果我错了,请有人纠正我。
<?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>
最后我的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>
非常感谢任何帮助。谢谢!
答案 0 :(得分:1)
使用Servlet 3+,您根本不需要使用web.xml,因为代码中提供了注释。因此,您可以根据需要删除该文件。如果您使用web.xml,它将覆盖您带注释的设置。
因此,请删除您的web.xml文件,并将value = "/*"
更改为urlPatterns = "/*"
注释中的@WebServlet
,然后重试。
如果仍然无法正常工作,则需要明确检查IntelliJ运行配置。您的服务器可能未在IDE中正确配置。