java 无法处理来自 Jar 的 jar 条目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39443450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to process jar entry from Jar
提问by user12495
I'm trying to run simple program on restful API and I'm getting the following Exception
我正在尝试在 restful API 上运行简单的程序,但出现以下异常
>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...
我的 web.xml 如下所示...
<?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;
}
}
回答by Himanshu Shukla
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
我有同样的错误。我在 java 8 中使用了 tomcat 8。我升级到 tomcat 9 并且问题解决了。猜测它与 java 8 中的一些新功能有关
回答by Ravi Samani
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.
你用的是哪个jdk版本?我在 1.8.0_92 之后尝试使用 jdk 版本,问题已为我解决。在此之前,由于 NoClassDefFoundError,我的 jar 工件无法构建。虽然编译显示有效的类存在。