w3c / epubcheck

The conformance checker for EPUB publications
https://www.w3.org/publishing/epubcheck/
BSD 3-Clause "New" or "Revised" License
1.65k stars 402 forks source link

Problem running EpubCheck with Spring Boot Application #758

Closed epubreader closed 1 year ago

epubreader commented 7 years ago

the same jar run on windows is fine, but has problem on linux server.

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.Error: Internal error: java.io.FileNotFoundException: JAR entry com/adobe/epubcheck/schema/30/./mod/datatypes.rnc not found in /app.jar!/BOOT-INF/lib/epubcheck-4.0.2.jar schema/30/ocf-container-30.rnc
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:978) ~[spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) [spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.5.14.jar!/:8.5.14]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) [spring-web-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.14.jar!/:8.5.14]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
Caused by: java.lang.Error: Internal error: java.io.FileNotFoundException: JAR entry com/adobe/epubcheck/schema/30/./mod/datatypes.rnc not found in /app.jar!/BOOT-INF/lib/epubcheck-4.0.2.jar schema/30/ocf-container-30.rnc
        at com.adobe.epubcheck.xml.XMLValidator.<init>(XMLValidator.java:262) ~[epubcheck-4.0.2.jar!/:4.0.2]
        at com.adobe.epubcheck.xml.XMLValidators.<init>(XMLValidators.java:56) ~[epubcheck-4.0.2.jar!/:4.0.2]
        at com.adobe.epubcheck.xml.XMLValidators.<clinit>(XMLValidators.java:6) ~[epubcheck-4.0.2.jar!/:4.0.2]
        at com.adobe.epubcheck.ocf.OCFChecker.<clinit>(OCFChecker.java:69) ~[epubcheck-4.0.2.jar!/:4.0.2]
        at com.adobe.epubcheck.api.EpubCheck.doValidate(EpubCheck.java:213) ~[epubcheck-4.0.2.jar!/:4.0.2]
        at com.adobe.epubcheck.api.EpubCheck.validate(EpubCheck.java:189) ~[epubcheck-4.0.2.jar!/:4.0.2]
        at com.springcms.book.controller.web.PublishController.validateEpub(PublishController.java:148) ~[classes!/:0.0.1-SNAPSHOT]
        at com.springcms.book.controller.web.PublishController.pendingApprove(PublishController.java:108) ~[classes!/:0.0.1-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]
        ... 31 common frames omitted
tofi86 commented 7 years ago

Seems to be related to #755.

Can you post your classpath please? Did you include ALL of the EpubCheck dependencies inyour project?

epubreader commented 7 years ago

I am using spring boot, run the program in the jar file, java -jar app.jar

jar:file:/app.jar!/BOOT-INF/lib/epubcheck-4.0.2.jar!/com/adobe/epubcheck/schema/30/./multiple-renditions/container.rnc

ResourceUtil

public static String getResourcePath(String localName) {
    String classPath = ResourceUtil.class.getName().replace('.', '/');
    String classPackage = classPath.substring(0, classPath.lastIndexOf("/"));
    String projectPackage = classPackage.substring(0, classPackage.lastIndexOf("/"));
    return projectPackage + "/" + localName;
}
tofi86 commented 7 years ago

You did not include the EpubCheck dependencies in your classpath.

If you download EpubCheck ZIP from the releases page https://github.com/IDPF/epubcheck/releases/tag/v4.0.2 you will find a lib/ folder with 13 jar libraries packed along with epubcheck.jar. All those libs need to be placed in your classpath.

Closing this as invalid because it's a configuration error.

epubreader commented 7 years ago

I am using maven, it is fine run in intellij,

    <dependency>
        <groupId>org.idpf</groupId>
        <artifactId>epubcheck</artifactId>
        <version>4.0.2</version>
    </dependency>

but after spring boot generate the fat jar app.jar with all the dependencies, it has this problem, I think it is not the classpath problem.

tofi86 commented 7 years ago

I'm not familiar with Spring, but it seems as if the FatJar does not contain all the epubcheck resources.

Can you check that the fatjar contains the schemas app.jar -> com/adobe/epubcheck/schema/30/? If not, the problem is your fatjar processing.

ctriebstein commented 7 years ago

I ran into the exact same issue and haven't found a solution yet.

I checked for the schemas and they are indeed included in the application jar but apparently spring boot is unable to find them.

tofi86 commented 7 years ago

Okay, I reopened the issue and someone has to review it and reproduce and debug it. Unfortunately it cannot be me, sorry.

@ctriebstein could you please post your classpath and make sure that all the EpubCheck dependencies are loaded? Probably make sure that the dependencies load before EpubCheck classes?

ctriebstein commented 7 years ago

I added the classpath to the attached file. Dependencies are loaded properly.

For some more information: I'm using a custom implementation of the Report class which I just updated from the 3.0.1 version to 4.0.2. The error occurs when calling the epubCheck.validate() method with the custom report.

If you need any code snippets, let me know.

cp.txt

ctriebstein commented 7 years ago

Additional Info: One of my recent changes was the update from spring boot 14.1-RELEASE to 1.5.1-RELEASE. I just tried a little something and reverted the version to 1.4.1-RELEASE and now it works as intended. Might be a spring boot issue with 1.5.1-RELEASE.

epubreader commented 7 years ago

it is because it is a nested jar, the below code will throw fileNotFoundException

@Test
public void submittingForm() throws Exception {

    URL url = new URL("jar:file:/D:/eclipse/web/target/web-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/epubcheck-4.0.2.jar!/com/adobe/epubcheck/schema/20/rng/container.rng");
    url.openStream();

}

and please check the code XMLValidator

rdeltour commented 5 years ago

Is this still an issue? To be honest I'm not sure I fully understand the problem here. If this is still causing trouble, could anyone rephrase the issue or provide a clear way to reproduce? Thanks!

Ridman commented 5 years ago

Reproduced with spring boot 1.4.4.RELEASE and 1.4.7.RELEASE. Works well with 1.5.19.RELEASE.

rdeltour commented 1 year ago

Closing (inactive).