2011-01-12 74 views
0

我有一個web應用程序(實際上是gwt應用程序),我想將它部署到Jetty服務器進行硒測試,我使用了maven,maven-jetty-plugin,gwt-maven-plugin和硒Maven的插件,我終於得到了碼頭和硒服務器運行,但Selenium測試失敗,因爲著名的404 eror的:如何部署web應用程序到碼頭

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

IM不知道如果我的碼頭配置是因爲即時通訊一種新的給它正確,這裏是(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時,我可以看到c ommand窗口:

[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頁面的右邊有文件夾「樣品 - 中console-0.1-SNAPSHOT',爲什麼找不到它?是因爲我設置'contextPath'錯誤?我試着將它設置爲'/',然後我得到503服務不可用的錯誤。任何人都可以幫忙非常感謝!!

回答

0

這聽起來像你試圖從webapp目錄運行應用程序,這將無法在GWT應用程序中工作。嘗試設置的目標在碼頭Maven插件來運行戰爭,而不是跑,是這樣的:

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

這將導致編譯和GWT編譯運行,假設你有這些配置。正確。

如果你的配置是這樣的,你可以只運行mvn clean integration-tests和你的腳本將:

  1. 編譯代碼
  2. GWT:編譯代碼
  3. 創建WAR文件
  4. 開始碼頭並將戰爭文件部署到碼頭
  5. 啓動Selenium服務器
  6. 嘗試在任何子目錄中運行任何測試測試目錄中的集成軟件包。