0

Hi I am new to maven and am not able to run my project. its throwing 404 for the mapped resources.

<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>

I have 2 classes :

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

}

these are the errors I am getting. Couldn't figure out what is wrong. Java compiler level does not match the version of the installed Java project facet. JAX-RS (REST Web Services) 2.0 requires Java 1.6 or newer.
One or more constraints have not been satisfied.

I am using jdk 1.8.0_111 I tried to put that in maven and tried ${jdk.version} I tried [1.8.0_111) also its giving same error. Its loading the welcome page correctly but giving 404 to the resource URI. is there something wrong in pom.xml?

@Path("hello")
public class MyResource {

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

for only 1.8 as compilance unit its not able to start 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"]
Sumit Sagar
  • 342
  • 1
  • 6
  • 17
  • did you try just `1.8` instead of `[1.8.0_111)`? does that work? – Naman Dec 15 '16 at 18:51
  • Please share the entire stack trace as to which line of code or building what module results in > Caused by: java.util.zip.ZipException – Naman Dec 15 '16 at 19:00
  • I deleted everything from .m2 folder and updated maven Now its not throwing error at 1.8 compilance but still getting 404. – Sumit Sagar Dec 15 '16 at 19:09
  • Can you show your web.xml? Have you defined the servlet container with resource package on it? – notionquest Dec 15 '16 at 19:10
  • @Sumitsagar I believe too many questions into one is not a good practice. Please try and decouple as you debug. – Naman Dec 15 '16 at 19:12
  • Actually I dont know what is causing the 404 in web page. previously I thought might be maven error. but i fixed that but still getting 404. – Sumit Sagar Dec 15 '16 at 19:35
  • @notionquest I dont have anything configured in web.xml. – Sumit Sagar Dec 15 '16 at 19:37
  • it worked. I had the jars in the .m2 folder corrupted, I deleted there updated the project and it ran. Thank you ALL. – Sumit Sagar Dec 15 '16 at 19:50

1 Answers1

0

Change

<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>

to

<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>

Post that if you see any exception, that needs to be resolved in the code.


Also make sure your jar file is not corrupted. If it's corrupted or not able to unzip, this error will occur. In such case try deleting the existing jar and build again.

Source - java.util.zip.ZipException: error in opening zip file

Community
  • 1
  • 1
Naman
  • 27,789
  • 26
  • 218
  • 353