Simon Hill created TOMEE-3982:
---------------------------------

             Summary: ServletContainerInitializer ignored by Tomee because of 
jar name and web-fragment "ordering"
                 Key: TOMEE-3982
                 URL: https://issues.apache.org/jira/browse/TOMEE-3982
             Project: TomEE
          Issue Type: Bug
          Components: TomEE Core Server
    Affects Versions: 8.0.12
         Environment: Window 10.0
            Reporter: Simon Hill


The behaviour I'm describing was detected on a applications running on Tomee 8 
(Apache Tomcat (TomEE)/9.0.63 (8.0.12)).

The library I'm maintaining contains a implementation of 
ServletContainerInitializer which is declared in 
META-INF/services/javax.servlet.ServletContainerInitializer file.

Recently I added the log4j-web dependency to the project. Before that my 
initializer was called as expected but since it is ignored.

After creating a minimal example I identified that my jar is ignored because :

  - Its name starts with spring- (it is not a library of the Spring Framework, 
only a poor naming choice) and,
  - Another jar in the classpath (log4j-web) contains a web-fragment.xml with 
"ordering" before or after "others" :

{code:xml}
  <web-fragment xmlns="http://java.sun.com/xml/ns/javaee";
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
                  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                                      
http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd";
                  version="3.0" metadata-complete="true">
    
        <name>my_web_fragment_xxx</name>
        <distributable />
        <ordering>
            <before>
                <others />
            </before>
        </ordering>
    </web-fragment>
{code}

*Minimal reproducible sample*
https://github.com/KWSimon/tomcat_jarscanning

I activated Tomcat traces logs and noticed that "spring" is listed in some 
exclusion prefixes as well as many other names.

{code}
    TRACE [Thread-2] 
org.apache.openejb.config.NewLoaderLogic.readDefaultExclusions Loaded 
default.exclusions
    TRACE [Thread-2] org.apache.openejb.config.NewLoaderLogic.logExclusions 
Exclusion prefixes: [
    ...
    TRACE [Thread-2] org.apache.openejb.config.NewLoaderLogic.logExclusions 
-snappy-java-
    TRACE [Thread-2] org.apache.openejb.config.NewLoaderLogic.logExclusions 
-spring-
    TRACE [Thread-2] org.apache.openejb.config.NewLoaderLogic.logExclusions 
-sshd-
    ...
{code}
I noticed that "google" is listed too and when I prefix my jar with "google-" 
it reproduces the same issue.

The default exclusion list comes from openejb-core library : 
https://github.com/apache/tomee/blob/c0928e2aed1713d16d28bffaed11ad5024bc3728/container/openejb-core/src/main/resources/default.exclusions

*Workarounds*
  - Rename the library (but it will have an impact on applications depending on 
it),
  - Add the name of the ignored jar to the 
tomcat.util.scan.StandardJarScanFilter.jarsToScan jars list (but it has to be 
done to every environments from dev to production for customers using our 
products).

*Question*
Why this issue is only triggered when a jar in the classpath contains a 
web-fragment with an <ordering> element ?


(ps : I submitted this bug on 'rzo1' suggestion after posting my question on 
Stackoverflow : 
https://stackoverflow.com/questions/40336878/maven-with-an-explicit-finalname-wont-work-properly)



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to