简体   繁体   中英

How to change default java methods

I'm facing some problems with my project (probably because windows, antivirus or both).

What's happening is the following error:

SEVERE: Exception Processing ErrorPage[errorCode=404, location=/404.jsp]
org.apache.jasper.JasperException: org.apache.jasper.JasperException: Unable to compile class for JSP
        at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:565)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)
        at org.apache.jasper.servlet.JspServlet._serviceJspFile(JspServlet.java:386)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:40001)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:472)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:395)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:316)
        at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:395)
        at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:254)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:177)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.jasper.JasperException: Unable to compile class for JSP
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:610)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:368)
        ... 26 more
Caused by: java.io.IOException: classFile.delete() failed
        at org.apache.jasper.compiler.SmapUtil$SDEInstaller.install(SmapUtil.java:204)
        at org.apache.jasper.compiler.SmapUtil.installSmap(SmapUtil.java:166)
        at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:510)
        at org.apache.jasper.compiler.Compiler.__compile(Compiler.java:379)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:41002)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:351)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)
        at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:595)
        ... 27 more

Looks like the file that classFile.delete() is trying to delete is in use.

We cannot add a exception in the antivirus....

I found a post from 2006 that says "My workaround was to modify the SmapUtil class. If the rename fails on the first try, it waits 50ms then retries (loops as needed). So far it always works on the second try after the 50ms delay."

My question is, where that SmapUtil class is located and how to edit that delete (and rename) methods?

I can't find this info anywhere

Thanks

Ensure you have Tomcat and Jasper configured for running in production.

To solve your specific issue you could set the Jasper option suppressSmap to true or precompile your JSP files , or both.

SMAP provides JSR-045 support for Jasper; It creates mappings from the generated bytecode back to the source JSP files to aid in debugging.

See this page for information on Jasper configuration.

I was able to "fix" it by changing that Tomcat method (delete and rename)

Looks like that whichever file it was trying to delete/rename, was being user by another process (likely antivirus)

So I cloned the source-code from Tomcat's Github, changed the class and voilá, it's working now.

That method was something like:

    if ( !classPath.delete(..) )
      throw Exception...

then I changed for something like:

    while ( !classPath.delete(..) && count < 10){
      Thread.wait(50);
      count++
    }

    if (count == 10) 
         Throw Exception

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM