javatomcatclassloaderhotdeploytomcat8.5

Can Tomcat (without hot deploy) ignore overridden jar


We are using Tomcat 8.5 without any hot deploy,

I assume that classes are loaded to memory and for example if class change in jar it will ignore (not hot deploy)

But if we override a jar when application is running it overrides classes (or removing it)

For example when I copy empty jar it throws ZipException for classes that were in the jar:

java.lang.IllegalStateException: java.util.zip.ZipException: zip file is empty
        at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.getArchiveEntry(AbstractSingleArchiveResourceSet.java:97)
        at org.apache.catalina.webresources.AbstractArchiveResourceSet.getResource(AbstractArchiveResourceSet.java:260)
        at org.apache.catalina.webresources.StandardRoot.getResourcesInternal(StandardRoot.java:327)
        at org.apache.catalina.webresources.CachedResource.validateResources(CachedResource.java:127)
        at org.apache.catalina.webresources.Cache.getResources(Cache.java:147)
        at org.apache.catalina.webresources.StandardRoot.getResources(StandardRoot.java:315)
        at org.apache.catalina.webresources.StandardRoot.getClassLoaderResources(StandardRoot.java:231)
        at org.apache.catalina.loader.WebappClassLoaderBase.findResources(WebappClassLoaderBase.java:939)
        at java.lang.ClassLoader.getResources(ClassLoader.java:1142)
        at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:348)
        at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)
        at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)
        at javax.xml.parsers.FactoryFinder$1.run(FactoryFinder.java:293)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:289)
        at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:267)
        at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:120)
        at com.MyHelper.createDoc(MyHelper.java:64)

Can tomcat ignore overridden jar and pull classes from memory only ?

Is there some sort of built-in hot deploy I'm not aware of?

EDIT

It may be related to issue specific for tomcat with empty jar opening


Solution

  • I think what is happening is that the classloader or the JAR file reader is reading and caching the JAR file's index. So if you replace the JAR file while the classloader is still open, and then attempt to load a resource, it is liable notice that the file is now empty.

    It may be related to issue specific for tomcat with empty jar opening

    No. Its is more fundamental. The standard Java classloaders are not designed cope with the JAR file changing.

    Can Tomcat ignore overridden jar and pull classes from memory only ?

    AFAIK no.

    But you may be able to implement your own custom class loader that did something like that; e.g.