0

我有一个网络应用程序(实际上是一个 gwt 应用程序),我想将它部署到 Jetty 服务器进行硒测试,我使用了 maven、maven-jetty-plugin、gwt-maven-plugin 和 selenium-maven-plugin,我终于得到了jetty 和 selenium 服务器正在运行,但 selenium 测试由于著名的 404 错误而失败:

com.thoughtworks.selenium.SeleniumException: XHR ERROR: URL = http://127.0.0.1:8080/index.html Response_Code = 404 Error_Message = Not Found

我不确定我的码头配置是否正确,因为我对它有点陌生,这是它(maven-jetty-plugin):

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>maven-jetty-plugin</artifactId>

  <configuration>
    <contextPath>/sample-console</contextPath>
    <webAppSourceDirectory>${basedir}/target/${project.artifactId}-${project.version}</webAppSourceDirectory>
    <webXml>${basedir}/target/${project.artifactId}-${project.version}/WEB-INF/web.xml</webXml>
  </configuration>
          <executions>
             <execution>
                <id>start-jetty</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                 <configuration>
                    <daemon>true</daemon>
                </configuration>
            </execution>
             <execution>
                <id>stop-jetty</id>
                <phase>post-integraion-test</phase>
                <goals>
                    <goal>stop</goal>
                </goals>
            </execution>
          </executions> 
</plugin>

当我运行 mvn clean install 时,我可以看到命令窗口的输出:

[INFO] Configuring Jetty for project: DYI sample Console
[INFO] Webapp source directory = /Users/dyi/Documents/workspace/sample/console/target/sample-console-0.1-SNAPSHOT
[INFO] Reload Mechanic: automatic
[INFO] Classes = /Users/dyi/Documents/workspace/sample/console/target/classes
log4j:WARN No appenders could be found for logger (org.mortbay.log).
log4j:WARN Please initialize the log4j system properly.
[INFO] Context path = /sample-console
[INFO] Tmp directory =  determined at runtime
[INFO] Web defaults = org/mortbay/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] web.xml file = /Users/dyi/Documents/workspace/sample/console/target/sample-console-0.1-SNAPSHOT/WEB-INF/web.xml
[INFO] Webapp directory = /Users/dyi/Documents/workspace/sample/console/target/sample-console-0.1-SNAPSHOT
[INFO] Starting jetty 6.1.22 ...
[INFO] Started Jetty Server
[INFO] [selenium:start-server {execution: start}]

我的文件夹结构如下所示:

--sample/
   -- console/
        -- src/
        -- target/
             -- classes/
             -- sample-console-0.1-SNAPSHOT/
                   -- css/
                   -- images/
                   -- img/
                   -- index.html
                   -- js/
                   -- META-INF/
                   -- security/
                   -- test.html
                   -- WEB-INF/ 
                         -- classes/
                         -- lib/
                         -- web.xml

我不明白的是我可以看到 index.html 页面就在文件夹“sample-console-0.1-SNAPSHOT”中,为什么找不到它?那是因为我设置了“上下文路径”错误吗?我尝试将其设置为“/”,然后出现 503 服务不可用错误。有人可以帮忙吗?非常感谢!!

4

1 回答 1

0

听起来您正试图从 webapp 目录中运行应用程序,这在 GWT 应用程序中不起作用。尝试在您的 jetty maven 插件中将目标设置为 run-war 而不是 run,如下所示:

<modelVersion>4.0.0</modelVersion>
<groupId>org.proj.web</groupId>
<artifactId>gwtapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>gwtapp</name>

<properties>
    ...
</properties>
<dependencies>
    ...
</dependencies>
<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <excludes>
                    <exclude>**/integration/**</exclude>
                </excludes>
            </configuration>
            <executions>
                <execution>
                    <id>integration-tests</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                        <excludes>
                            <exclude>none</exclude>
                        </excludes>
                        <includes>
                            <include>**/integration/**
                    </include>
                        </includes>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <!-- Selenium and integration testing support -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>selenium-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>                
                <execution>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>start-server</goal>
                    </goals>
                    <configuration>
                        <background>true</background>
                    </configuration>
                </execution>
                <execution>
                    <id>stop</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop-server</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>   
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>7.2.2.v20101205</version>
            <configuration>
                <webAppConfig>
                    <contextPath>/${project.name}</contextPath>
                </webAppConfig>
                <scanIntervalSeconds>5</scanIntervalSeconds>
                <stopPort>9966</stopPort>
                <stopKey>foo</stopKey>
                <connectors>
                    <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                        <port>9080</port>
                        <maxIdleTime>60000</maxIdleTime>
                    </connector>
                </connectors>
            </configuration>
            <executions>
                <execution>
                    <id>start-jetty</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run-war</goal>
                    </goals>
                    <configuration>
                        <daemon>true</daemon>
                    </configuration>
                </execution>
                <execution>
                    <id>stop-jetty</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>2.1.0-1</version>
            <configuration>
                <logLevel>INFO</logLevel>
                <style>PRETTY</style>
                <runTarget>/gwtapp.html</runTarget>
                <hostedWebapp>${project.build.directory}/${project.build.finalName}</hostedWebapp>
                <modules>
                    <module>${project.groupId}.gwtapp</module>
                </modules>
                <copyWebapp>true</copyWebapp>
            </configuration>
            <executions>
                <execution>
                    <id>gwtcompile</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
</build>

这将导致 compile 和 gwt-compile 运行。假设您已正确配置它们。

如果您的配置看起来像这样,您可以运行mvn clean integration-tests并且您的脚本将:

  1. 编译你的代码
  2. gwt:编译你的代码
  3. 创建战争文件
  4. 启动jetty并将war文件部署到jetty
  5. 启动 Selenium 服务器
  6. 尝试在测试目录中的集成包的任何子目录中运行任何测试。
于 2011-02-11T20:50:15.680 回答