创建Jersey项目后重命名包

时间:2015-10-23 16:20:29

标签: java maven jersey

我有3个月前创建的Glassfish Jersey项目。我可以从我的localhost请求它,但是在将包从org.busTracker.serverSide重命名为'org.busTracker.trackingService'之后,我遇到了让它工作的问题。我按下F2按钮后将其重命名,但我没有通过chrome postmann插件获得请求。

我还要在哪里重命名才能让它发挥作用?

重命名包后出现

错误消息:

<!DOCTYPE html>
<html>
    <head>
        <title>Apache Tomcat/8.0.22 - Error report</title>
        <style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style>
    </head>
    <body>
        <h1>HTTP Status 404 - Not Found</h1>
        <div class="line"></div>
        <p>
            <b>type</b> Status report
        </p>
        <p>
            <b>message</b>
            <u>Not Found</u>
        </p>
        <p>
            <b>description</b>
            <u>The requested resource is not available.</u>
        </p>
        <hr class="line">
            <h3>Apache Tomcat/8.0.22</h3>
        </body>
    </html>

pom.xml文件:

**pom.xml**

        <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/maven-v4_0_0.xsd">

        <modelVersion>4.0.0</modelVersion>

        <groupId>org.busTracker</groupId>
        <artifactId>serverSide</artifactId>
        <packaging>war</packaging>
        <version>0.0.1-SNAPSHOT</version>
        <name>serverSide</name>

        <build>
            <finalName>serverSide</finalName>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.5.1</version>
                    <inherited>true</inherited>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>

        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.glassfish.jersey</groupId>
                    <artifactId>jersey-bom</artifactId>
                    <version>${jersey.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>

        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey.containers</groupId>
                <artifactId>jersey-container-servlet-core</artifactId>
                <!-- use the following artifactId if you don't need servlet 2.x compatibility -->
                <!-- artifactId>jersey-container-servlet</artifactId -->
            </dependency>
            <dependency>
                <groupId>org.glassfish.jersey.media</groupId>
                <artifactId>jersey-media-json-jackson</artifactId>
                <version>2.16</version>
            </dependency>
            <!-- uncomment this to get JSON support <dependency> <groupId>org.glassfish.jersey.media</groupId> 
                <artifactId>jersey-media-moxy</artifactId> </dependency> -->
        </dependencies>
        <properties>
            <jersey.version>2.16</jersey.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    </project>

屏幕截图

enter image description here

1 个答案:

答案 0 :(得分:1)

查看您的web.xml文件。你会看到

<init-param>
    <param-name>jersey.config.server.provider.packages</param-name>
    <param-value>org.busTracker.serverSide</param-value>
</init-param>

此属性告诉Jersey扫描org.busTracker.serverSide包中的资源类。如果您更改资源包,那么Jersey无法找到它们。所以只需更改web.xml中的包