title: Tomcat 7 + Annotations in log4j-api-2.11.1.jar
body: <p>I get this exception from tomcat upon startup of the war file:</p>
  
  <pre><code>Unable to process Jar entry [META-INF/versions/9/module-info.class] from Jar [jar:file:/C:/tomcat/apache-tomcat-7.0.61/webapps/monitormonitor/WEB-INF/lib/log4j-api-2.11.1.jar!/] for annotations
  org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in
  constant pool: 19
      at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:97)
  </code></pre>
  
  <p>I tried to switch the log4j to an older version in the pom.xml, but failed, it still scans log4j-api-2.11.1.jar.
  I added metadata-complete="true" to the tomcats web.xml but this didn't change the error.</p>
  
  <p>I read other pages on stackoverflow, but it didn't resolve my problem:</p>
  
  <p><a href="https://stackoverflow.com/questions/32864778/tomcat-7-and-java-8-compatibility-issue">Tomcat 7 and Java 8 compatibility issue</a></p>
  
  <p><a href="https://stackoverflow.com/questions/52867430/invalid-byte-tag-in-constant-pool-19-error-message">Invalid byte tag in constant pool: 19 error message</a></p>
  
  <p>The latter seems to have a good answer, but I don't understand how to exclude files from annotation scanning, and I also do not know how excluding files affects the functionality of the web application.</p>
  
  <p>Please find attached my pom.xml. It includes some of my attempts to fix this in a commented out version.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.1.2.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.xxx&lt;/groupId&gt;
      &lt;artifactId&gt;monitormonitor&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;monitormonitor&lt;/name&gt;
      &lt;description&gt;Web Service Monitoring project for Spring Boot&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;packaging&gt;war&lt;/packaging&gt;
  
      &lt;dependencies&gt;
          &lt;!-- added recent version of icu4j and log4j for invalid byte tag error --&gt;
          &lt;!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
              &lt;!-- changed version vs. ClassFormatException: Invalid byte tag in constant pool: 19 --&gt;
              &lt;!--&lt;version&gt;2.11.1&lt;/version&gt;--&gt;
              &lt;version&gt;2.7&lt;/version&gt;
              &lt;!--&lt;scope&gt;provided&lt;/scope&gt;--&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
              &lt;scope&gt;provided&lt;/scope&gt;&lt;!-- changed --&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;!-- duplicate
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
          &lt;/dependency&gt;
          --&gt;
          &lt;!--
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          --&gt;
          &lt;!-- added recent version of icu4j and log4j for invalid byte tag error --&gt;
          &lt;!-- https://mvnrepository.com/artifact/com.ibm.icu/icu4j --&gt;
          &lt;!--&lt;dependency&gt;
              &lt;groupId&gt;com.ibm.icu&lt;/groupId&gt;
              &lt;artifactId&gt;icu4j&lt;/artifactId&gt;
              &lt;version&gt;63.1&lt;/version&gt;
          &lt;/dependency&gt;
          --&gt;
  
          &lt;!-- added this dependency vs. ClassFormatException: Invalid byte tag in constant pool: 19 --&gt;
          &lt;!-- https://mvnrepository.com/artifact/org.aspectj/aspectjtools --&gt;
          &lt;!--             &lt;dependency&gt;
                          &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
                          &lt;artifactId&gt;aspectjtools&lt;/artifactId&gt;
                          &lt;version&gt;1.9.1&lt;/version&gt;
                      &lt;/dependency&gt;
          --&gt;
                      &lt;!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver --&gt;
          &lt;!--         &lt;dependency&gt;
                          &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
                          &lt;artifactId&gt;aspectjweaver&lt;/artifactId&gt;
                          &lt;version&gt;1.9.1&lt;/version&gt;
                      &lt;/dependency&gt;
          --&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>I would prefer a solution where I don't have to upgrade the tomcat.
  My tomcat version is apache-tomcat-7.0.61.</p>