2012-05-12 94 views
2

我有一個運行良好的servlet,直到前幾天。但我唯一改變的是我用於maven的nexus回購。我通過MVN碼頭運行servlet:運行在Jetty中運行servlet時獲取HTTP 500

但是當我嘗試訪問該網站,而不是看到主頁,我看到:

HTTP ERROR 500 

Problem accessing /. Reason: 

    jregex/Pattern 

我可以訪問其他網址的細如/圖標.ICO。但是我無法找到任何關於這個jregex/Pattern錯誤的東西,它看起來並沒有像代碼中一樣使用jregex庫。

我也看不到日誌中有任何問題。它看起來像主頁的請求不是我的servlet,但其他網頁的請求是。

這兩個拱Linux和Mac OS X 10.7

發生這是幾乎可以肯定的依賴問題,因爲它的工作原理(從舊關係服務器依賴)與一箇舊更換我~/.m2文件夾後。

有時候,我也得到:

HTTP ERROR: 503 

Problem accessing /. Reason: 

    SERVICE_UNAVAILABLE 
+0

什麼操作系統?確保服務器有權訪問這些文件。 –

+0

這是在Linux和Mac上(特別是Arch Linux和Mac OS X 10.7)。我doublechecked的權限,但我仍然得到同樣的事情。 –

+0

您的WAR web.xml正確嗎?看看Jetty日誌文件 –

回答

1

我會先從比較之前創建的ear/war文件,你改變了你的pom.xml後。這應該會導致你的jar文件被更改。假設一切都是開源的,從Maven回購下載源並比較它們。 \

編輯:JRegex是一個支持Perl regexp的java庫。 也許更改maven repo會導致下載其他版本的依賴項,並且它們對JRegex有一些可選的依賴項。 (你應該能夠檢查)。

嘗試將JRegex添加到您的依賴項並查看會發生什麼。 (注意,這是對子級一種變通方法,如果你在生產和趕時間)

+0

謝謝!我90%確定我現在已經解決了。比較戰爭的兩個版本讓我注意到正在使用不同版本的uasparser。 2012-02-08使用的良好版本,2012-05-09使用的版本較差。這個改變是由其他人做出的,我沒有充分研究它,因爲我沒有意識到這是一個應用級失敗,而不是碼頭級。 –

0

什麼是你正在運行mvn命令?您是否嘗試過手動下載工件並在本地工件上運行mvn?

我首先使用mvn來下載工件。這將驗證您的所有設置/權限設置是否適用。爲此,您可以使用Maven Dependency Plugin (v2.4)將依賴關係下載到本地文件。有關更多詳細信息,請參見this post

確保您可以在本地下載工件後,嘗試運行jetty:在本地工件上運行。如果有效,那麼你知道你在回購時遇到了麻煩。

如果仍然無法正常工作,則可能無法使用鏡像設置或回購配置。例如,如果mvn需要一個本地沒有的插件或依賴項,則它將顯示第三方回購。您的settings.xml文件可能將所有內容鏡像到您的本地nexus服務器,該服務器可能未配置爲從MvnCentral下載。

確保您沒有任何依賴關係/插件下載問題。您可以從settings.xml輕鬆地指向mvncentral,並完全繞過您的nexus服務器。

2

傑森這裏對我來說是什麼工作,這是我用很多時候,pom.xml文件(相關部分):

<dependencies> 
     <!-- Jetty dependencies --> 
     <dependency> 
      <groupId>org.mortbay.jetty</groupId> 
      <artifactId>jetty-embedded</artifactId> 
      <version>6.1.26</version> 
     </dependency> 
    </dependencies> 

    <build> 
    <plugins> 
     <plugin> 
      <groupId>org.mortbay.jetty</groupId> 
      <artifactId>jetty-maven-plugin</artifactId> 
      <version>7.0.2.v20100331</version> 
      <configuration> 
       <webAppConfig> 
        <contextPath>/jetty-example</contextPath> 
        <descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor> 
       </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> 
     </plugin> 
    </plugins> 
    </build> 

這裏是位於上述webappconfig指定的位置在web.xml描述:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
    version="2.4"> 

    <display-name>HelloWorld Application</display-name> 
    <description> 
     lalala 
    </description> 

    <servlet> 
     <servlet-name>HelloServlet</servlet-name> 
     <servlet-class>com.mypackage.jetty.Hello</servlet-class> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>HelloServlet</servlet-name> 
     <url-pattern>/hello</url-pattern> 
    </servlet-mapping> 

</web-app> 

並且servlet本身:

public final class Hello extends HttpServlet { 

    private static final long serialVersionUID = 903359962771189189L; 

    public void doGet(HttpServletRequest request, 
         HttpServletResponse response) 
     throws IOException, ServletException { 

     response.setContentType("text/html"); 
     PrintWriter writer = response.getWriter();   
     writer.println("<html>"); 
     writer.println("<head>"); 
     writer.println("<title>Sample Application Servlet Page</title>"); 
     writer.println("</head>"); 
     writer.println("<body bgcolor=white>"); 

     writer.println("<table border=\"0\" cellpadding=\"10\">"); 
     writer.println("<tr>"); 
     writer.println("<td>"); 
     writer.println("</td>"); 
     writer.println("<td>"); 
     writer.println("<h1>W00w I totally work</h1>"); 
     writer.println("</td>"); 
     writer.println("</tr>"); 
     writer.println("</table>"); 

     writer.println("</body>"); 
     writer.println("</html>"); 
    } 
} 

您可以運行SERV呃運行mvn jetty:run並檢查它在http://localhost:9080/jetty-example/hello

此外,您可以添加執行插件部分,並啓動碼頭,當你finnish建設你的項目。無需每次都手動輸入mvn jetty:run

<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-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> 
</executions> 

您可以額外添加我用於數據庫(針對不同環境)的jetty配置文件。你會在你的碼頭插件的webAppConfig這樣添加的文件位置:碼頭-env.xml的

<webAppConfig> 
     <contextPath>/my-tool</contextPath> 
     <descriptor>${basedir}/src/main/webapp/WEB-INF/jetty/web.xml       </descriptor> 
     <jettyEnvXml>${basedir}/src/main/webapp/WEB-INF/jetty/jetty-env.xml       </jettyEnvXml> 
</webAppConfig> 

而且樣本量:

<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"[]> 
<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext"> 
     <!-- PRIMARY DATABASE  --> 
     <New id="devDS" class="org.eclipse.jetty.plus.jndi.Resource"> 
      <Arg>primaryDS</Arg> 
      <Arg> 
        <!-- i.e. Postgress --> 
        <New class="org.postgresql.ds.PGSimpleDataSource"> 
         <Set name="User">myuser</Set> 
         <Set name="Password">password</Set> 
         <Set name="DatabaseName">database</Set> 
         <Set name="ServerName">database.stackoverflow.com</Set> 
         <Set name="PortNumber">5432</Set> 
        </New> 
      </Arg> 
     </New> 
     <!-- BACKUP DATABASE  
     <New id="devDS" class="org.eclipse.jetty.plus.jndi.Resource">   
     <Arg>backupDS</Arg>  
     <Arg>    
      .....  
     </Arg>  
     --> 
</Configure> 

你要善於與此有關。

+1

感謝您的詳細解釋,但事實證明,這實際上是一個應用程序級別的問題,而不是碼頭級別。 –

+0

@JasonAxelson kewl,很高興的事情得到解決 – ant

相關問題