2016-06-27 6 views
0

私はジャージーWebサービスを作成し、それをtomcatアプリケーションサーバーにデプロイしました。私はtomcatにwarファイルをデプロイしましたが、アプリケーションにアクセスしようとすると、要求されたデータが見つからないというエラーが発生しました(標準のtomcat 404エラー)。これは私のweb.xmlファイルです。Javaジャージーはリソースを見つけることができません

<?xml version="1.0" encoding="UTF-8"?> 

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd」 ID = "WebApp_ID" バージョン= "2.5"> ジャージーindex.htmlを

<servlet> 
    <servlet-name>Jersey REST Service</servlet-name> 
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> 
    <init-param> 
     <param-name>com.sun.jersey.config.property.packages</param-name> 
     <param-value>sample.jsonStrip.resources</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>RestServlet</servlet-name> 
    <url-pattern>/rest/*</url-pattern> 
</servlet-mapping> 

これは

http://maven.apache.org/xsd/maven-4.0.0.xsd "> 0私のpom.xmlです4.0.0 org.rares.urs ジャージー 0.0.1-SNAPSHOT 成分xmlファイルの

<repositories> 
    <repository> 
     <id>maven2-repository.java.net</id> 
     <name>Java.net Repository for Maven</name> 
     <url>http://download.java.net/maven/2/</url> 
     <layout>default</layout> 
    </repository> 
</repositories> 
<packaging>war</packaging> 

<build> 
    <finalName>JsonStrip</finalName> 

    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.1</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 

     <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.4</version> 
      <configuration> 
       <warSourceDirectory>WebContent</warSourceDirectory> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
      </configuration> 
     </plugin> 

     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>tomcat-maven-plugin</artifactId> 
      <configuration> 
       <url>http://127.0.0.1:8888/manager</url> 
       <server>mytomcat</server> 
       <path>/Jersey</path> 
      </configuration> 
     </plugin> 


     <plugin> 
      <groupId>org.apache.tomcat.maven</groupId> 
      <artifactId>tomcat8-maven-plugin</artifactId> 
      <version>2.2</version> 
      <configuration> 
       <url>http://127.0.0.1:8888/manager</url> 
       <server>TomcatServer</server> 
       <path>/Switch</path> 
      </configuration> 
     </plugin> 

    </plugins> 
</build> 

<dependencies> 
    <dependency> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-jar-plugin</artifactId> 
     <version>3.0.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-dependency-plugin</artifactId> 
     <version>2.9</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
    </dependency> 
    <dependency> 
     <groupId>com.fasterxml.jackson.jaxrs</groupId> 
     <artifactId>jackson-jaxrs-json-provider</artifactId> 
     <version>2.7.0</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.ws.rs</groupId> 
     <artifactId>javax.ws.rs-api</artifactId> 
     <version>2.0.1</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-war-plugin</artifactId> 
     <version>2.6</version> 
    </dependency> 
    <dependency> 
     <groupId>org.codehaus.jackson</groupId> 
     <artifactId>jackson-mapper-asl</artifactId> 
     <version>1.9.2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.codehaus.jackson</groupId> 
     <artifactId>jackson-core-asl</artifactId> 
     <version>1.9.2</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-client</artifactId> 
     <version>1.8</version> 
    </dependency> 
    <dependency> 
     <groupId>org.glassfish.jersey.core</groupId> 
     <artifactId>jersey-common</artifactId> 
     <version>2.22.2</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>asm</groupId> 
     <artifactId>asm</artifactId> 
     <version>3.3.1</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-bundle</artifactId> 
     <version>1.19</version> 
    </dependency> 
    <dependency> 
     <groupId>org.json</groupId> 
     <artifactId>json</artifactId> 
     <version>20140107</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-server</artifactId> 
     <version>1.19</version> 
    </dependency> 
</dependencies> 

どちらも、ジャージーのルートフォルダにしています。 wab.xmlがWebContent/WEB-INF/web.xmlにある場合があります。どこに置くべきですか?

ありがとうございます!

+0

これには多くの理由があります。起動時にログには何が表示されますか?どのURLにヒットしましたか? pom.xmlにいくつかの問題があります。 Web.xmlはWEB-INF/web.xmlに配置する必要があります。 – Stefan

+0

私はそこにweb.xmlを持っていますが、それは私が作成したものでコンテンツを置き換えるべきですか?私はhttp://127.0.0.1:8889/JsonStrip/r​​est/jerseyに行きますが、可能なすべての組み合わせを試しました。 pomにはどのようなエラーがありますか? –

+0

web.xmlの ''は、両方の場所で一致する必要があります。 –

答えて

0

web.xmlの<servlet-name><servlet-mapping>では、両方の場所で

と一致する必要があり、<servlet-name>は、このマッピングは同じ<servlet-name><servlet>を探すことによって、に適用するべきか、サーブレットコンテナに指示します。現在、JerseyサーブレットにはURLマッピングがないため、リクエストは処理されません。

wab.xmlがWebContent/WEB-INF/web.xmlにある場合がありますか?どこに置くべきですか?

そこ。私はしばらくの間、eclipseを使用していませんが、WebContentフォルダーは "本当の"フォルダーではないと確信しています。これはIDEディスプレイフォルダのみです。 Mavenアプリケーションでは、実際のディレクトリ構造をsrc/main/webappにマッピングする必要があります。 web.xmlはどこにあるのですかsrc/main/webapp/WEB-INF

+0

両方のタグの名前をRestServletに置き換えたので、アプリはhttp://127.0.0.1:8889/Jersey/RestServlet/(and_the_path_to_a_class)で起動するようになりましたか? –

+0

どちらか、 'Jersey'を' JsonStrip'に置き換えてください。あなたのEclipseコンテキスト設定に依存します –

+0

ありがとう!多分私のフォルダ構造が間違っていて、私は同じエラーを受けています。 –

関連する問題