Unable to process jar entry from Jar

2019-07-12 18:56发布

问题:

I'm trying to run simple program on restful API and I'm getting the following Exception

>Sep 12, 2016 10:05:02 AM org.apache.catalina.startup.ContextConfig processAnnotationsJar
SEVERE: Unable to process Jar entry [javassist/tools/rmi/RemoteRef.class] from Jar [jar:file:/C:/Users/user/examples/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/demoWebservice/WEB-INF/lib/javassist-3.19.0-GA.jar!/] for annotations
java.io.EOFException
    at java.io.DataInputStream.readUnsignedShort(Unknown Source)
    at org.apache.tomcat.util.bcel.classfile.Utility.swallowMethodParameters(Utility.java:797)
    at org.apache.tomcat.util.bcel.classfile.Attribute.readAttribute(Attribute.java:171)
    at org.apache.tomcat.util.bcel.classfile.FieldOrMethod.<init>(FieldOrMethod.java:57)
    at org.apache.tomcat.util.bcel.classfile.Method.<init>(Method.java:71)
    at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:267)
    at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:127)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2058)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1934)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1900)
    at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1885)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1317)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:876)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5378)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
    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)

My web.xml is shown below...

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>demoWebservice</display-name>

    <servlet>
    <servlet-name>Java WS</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>jersy.config.server.provider.packages</param-name>
      <param-value>book</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>Java WS</servlet-name>
    <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

class is shown below:-

package book;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/book")
public class Book {

    @GET
    @Produces(MediaType.TEXT_XML)
    public String sayHelloXML(){
        String response = "<?xml version='1.0'?>"
                + "<hello> Hello World </hello>";
        return response;
    }

}

回答1:

Which jdk version you are using? I tried with jdk version after 1.8.0_92 and issue got resolved for me. Before that my jar artifacts were not able to build due to NoClassDefFoundError. Though compilation shown valid class existence.



回答2:

I had the same error.I was using tomcat 8 with java 8 .I upgraded to tomcat 9 and the problem was solved.Guess it has something to do with some new feature in java 8