运行WAR文件时出现Tomcat 404错误

时间:2014-04-18 16:20:28

标签: java tomcat

我收到“请求的资源不可用”。在Tomcat 7中部署我的战争时的消息。

以下是详细信息。

1] WAR的名称= devMonitor-1.war

2] web.xml 如下:

<?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>main</display-name>
    <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>main.java</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>

3]我的泽西RS等级

*package main.java;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
//Sets the path to base URL + /hello
**@Path("/hello")**
public class Hello {
    // This method is called if TEXT_PLAIN is request
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String sayPlainTextHello() {
        return "Hello Jersey";
    }
    // This method is called if XML is request
    @GET
    @Produces(MediaType.TEXT_XML)
    public String sayXMLHello() {
        return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
    }
    // This method is called if HTML is request
    @GET
    @Produces(MediaType.TEXT_HTML)
    public String sayHtmlHello() {
        return "<html> " + "<title>" + "Hello Jersey" + "</title>" + "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
    }
    }*

4] URL我试图点击= localhost:8080 / main / rest / hello

5] POM文件,如果有以下任何内容

<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>com.travelport.soa.svcs.pos.uapi.devMonitor</groupId>
    <artifactId>devMonitor</artifactId>
    <version>1</version>
    <packaging>war</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>2.7</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet-core</artifactId>
            <version>2.7</version>
        </dependency>

    </dependencies>
</project>

6]我的tomcat监视器显示app运行如下,但仍然无法运行。

Path        Version     Display Name        Running     Sessions

/devMonitor-1   None specified  main            true        0   

1 个答案:

答案 0 :(得分:0)

部署WAR文件时很少有人知道。

TRY:
从命令行或管理器应用程序重新部署WAR文件。耐心点。如果您的WAR文件很大,这可能需要几分钟时间。观察任务管理器,看看Tomcat正在使用多少CPU。如果使用90%或更多,则可能无法完成部署过程。

如果重新部署不起作用,请停止tomcat,删除WAR文件,在Web应用程序文件夹中放置一个新的WAR文件,重新启动Tomcat并等待部署过程完成。