REST给404

时间:2016-12-15 18:47:13

标签: java rest maven

嗨,我是maven的新手,无法运行我的项目。它为映射的资源抛出了404.

<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>com.sumit.adjax</groupId>
<artifactId>advanced-jaxrs</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>advanced-jaxrs Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.bundles</groupId>
        <artifactId>jaxrs-ri</artifactId>
        <version>2.16</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-moxy</artifactId>
        <version>2.16</version>
    </dependency>
</dependencies>
<build>
    <finalName>advanced-jaxrs</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <source>[1.8.0_111)</source>
                <target>[1.8.0_111)</target>
            </configuration>
        </plugin>
    </plugins>
</build>


<properties>
    <jersey.version>2.16</jersey.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

我有2个班级:

@ApplicationPath("webapi")
public class MyApp extends Application {

}

这些是我得到的错误。无法弄清楚出了什么问题。     Java编译器级别与已安装的Java项目构面的版本不匹配。     JAX-RS(REST Web服务)2.0需要Java 1.6或更高版本     一个或多个约束条件尚未得到满足。

我正在使用jdk 1.8.0_111我试图把它放在maven中并尝试了$ {jdk.version}我试过[1.8.0_111]也给出了同样的错误。 它正确加载欢迎页面但给404资源URI。 在pom.xml中有什么问题吗?

@Path("hello")
public class MyResource {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String testMethod() {
    return "Hello World";
    }
}

只有1.8作为编纂单位,它无法启动tomcat。

Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)
at java.util.zip.ZipFile.read(Native Method)
at java.util.zip.ZipFile.access$1400(Unknown Source)
at java.util.zip.ZipFile$ZipFileInputStream.read(Unknown Source)
at java.util.zip.ZipFile$ZipFileInflaterInputStream.fill(Unknown Source)
at java.util.zip.InflaterInputStream.read(Unknown Source)
at sun.misc.IOUtils.readFully(Unknown Source)
at java.util.jar.JarFile.getBytes(Unknown Source)
at java.util.jar.JarFile.getManifestFromReference(Unknown Source)
at java.util.jar.JarFile.getManifest(Unknown Source)
at org.apache.catalina.webresources.JarResourceSet.initInternal(JarResourceSet.java:137)
... 13 more

Dec 16, 2016 12:19:27 AM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException:     org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at java.util.concurrent.FutureTask.report(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:911)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:791)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
at org.apache.catalina.startup.Catalina.start(Catalina.java:655)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:355)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:495)
  Caused by: org.apache.catalina.LifecycleException: Failed to start   component [StandardEngine[Catalina].StandardHost[localhost]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158)
at    org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403)
at    org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
  Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at   org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:920)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:890)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
... 6 more

  Dec 16, 2016 12:19:27 AM org.apache.catalina.startup.Catalina start
  SEVERE: The required Server component failed to start so Tomcat is unable to start.
org.apache.catalina.LifecycleException: Failed to start component    [StandardServer[8005]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158)
at org.apache.catalina.startup.Catalina.start(Catalina.java:655)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:355)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:495)
   Caused by: org.apache.catalina.LifecycleException: Failed to start  component             [StandardService[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158)
at   org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:791)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
... 9 more
 Caused by: org.apache.catalina.LifecycleException: A child container failed  during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:920)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
... 11 more

 Dec 16, 2016 12:19:27 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-nio-8080"]
Dec 16, 2016 12:19:27 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-nio-8009"]
Dec 16, 2016 12:19:27 AM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Dec 16, 2016 12:19:27 AM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-nio-8080"]
Dec 16, 2016 12:19:27 AM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-nio-8009"]

1 个答案:

答案 0 :(得分:0)

更改

<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.6.0</version>
      <configuration>
          <source>[1.8.0_111)</source>
          <target>[1.8.0_111)</target>
      </configuration>
</plugin>

<plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.6.0</version>
      <configuration>
          <source>1.8</source>
          <target>1.8</target>
      </configuration>
</plugin>

发布如果您发现任何异常,则需要在代码中解决。

还要确保您的jar文件没有损坏。如果它已损坏或无法解压缩,则会发生此错误。在这种情况下,请尝试删除现有的jar并重新构建。

来源 - java.util.zip.ZipException: error in opening zip file