【问题标题】:Unable to find log4j jar parent dependency找不到 log4j jar 父依赖项
【发布时间】:2022-01-16 20:38:43
【问题描述】:

我正在使用 Maven 3.6.0,并且我有 Spring Boot Maven 项目,其 pom 文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    
    <groupId>com.myapp</groupId>  
    <artifactId>myAppName</artifactId> 
    <version>1</version>
    <packaging>war</packaging>    

    <parent>   
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>   
    </properties>

    <dependencies>
    
       

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId> 
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>

        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        
        

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-ldap</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.directory.server</groupId>
            <artifactId>apacheds-server-jndi</artifactId>
            <version>1.5.7</version>
        </dependency>
        
        
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>8.2.1.jre8</version>
        </dependency>
        
         
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.faces</artifactId>
            <version>2.3.9</version>
        </dependency>
        
         
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>10.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.primefaces.extensions</groupId>
            <artifactId>primefaces-extensions</artifactId>
            <version>10.0.0</version>
        </dependency>


        <dependency>
            <groupId>org.primefaces.extensions</groupId>
            <artifactId>resources-ckeditor</artifactId>
            <version>10.0.0</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.ocpsoft.rewrite</groupId>
            <artifactId>rewrite-servlet</artifactId>
            <version>3.4.4.Final</version>
        </dependency>

        <dependency>
            <groupId>org.ocpsoft.rewrite</groupId>
            <artifactId>rewrite-config-prettyfaces</artifactId>
            <version>3.4.4.Final</version>
        </dependency>
        
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.14</version>
        </dependency> 
            
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.5</version>
        </dependency>
                        
        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
            <version>1.6</version>
        </dependency>
        
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.4</version>
        </dependency>
        
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.7</version>
        </dependency>
            
        
            
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.2</version>
        </dependency>
        
        
        <dependency>
          <groupId>org.primefaces</groupId> 
          <artifactId>california-theme</artifactId>
          <version>2.0.1</version>
        </dependency>
        
        <dependency>
          <groupId>SadadMC</groupId> 
          <artifactId>SadadMC</artifactId>
          <version>1.0</version>
        </dependency>
        
        <dependency>
          <groupId>Jace</groupId> 
          <artifactId>Jace</artifactId> 
          <version>5.2.1</version>
        </dependency>
        
        <dependency>
          <groupId>stax-api</groupId> 
          <artifactId>stax-api</artifactId> 
          <version>5.2.1</version>
        </dependency>
        
        <dependency>
          <groupId>xlxpScanner</groupId> 
          <artifactId>xlxpScanner</artifactId> 
          <version>5.2.1</version>
        </dependency>
        
        <dependency>
          <groupId>xlxpScannerUtils</groupId> 
          <artifactId>xlxpScannerUtils</artifactId> 
          <version>5.2.1</version>
        </dependency>
        
        
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-1.2-api</artifactId>
            <version>2.15.0</version>
        </dependency>
        
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.15.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.15.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.17</version>
        </dependency>
        
        
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
        </dependency>
            
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
            <version>4.4</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.5</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-core</artifactId>
            <version>1.24.1</version>
        </dependency>
        
    </dependencies>
    
    <build>
        <finalName>myAppName</finalName>    
        <plugins>
            
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-surefire-plugin</artifactId>          
               <configuration>
                  <argLine>-Dfile.encoding=UTF8</argLine>
                  <skipTests>true</skipTests>
               </configuration>
            </plugin>
            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.1</version>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>${basedir}/src/main/java</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <includes>
                                <include>**/*.properties</include>
                                <include>**/*.xml</include>
                                <include>**/*.css</include>
                                <include>**/*.html</include>
                            </includes>
                        </resource>
                        <resource>
                            <directory>${basedir}/lib</directory>
                            <targetPath>WEB-INF/lib</targetPath>
                            <includes>
                                <include>**/*.jar</include>
                            </includes>
                        </resource>
                    </webResources>
                    <!--  <outputDirectory>C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps</outputDirectory> -->
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

        </plugins>
         
    </build>
    
    

    <repositories>
    
       <repository>
            <id>java-net-repo</id>
            <url>https://maven.java.net/content/repositories/public/</url>
        </repository>
        
       <repository>
          <id>central</id>
          <name>Central Repository</name>
          <url>https://repo.maven.apache.org/maven2</url>
          <layout>default</layout>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
        
        <repository>
            <id>itext-releases</id>
            <name>iText Repository - releases</name>
            <url>https://repo.itextsupport.com/releases</url>
          </repository>
        <repository>
            <id>Enonic</id>
            <name>Enonic</name>
            <url>https://repo.enonic.com/public/</url>
        </repository>
        <repository>
            <id>central-repo</id>
            <name>Central Repository</name>
            <url>http://insecure.repo1.maven.org/maven2</url>
        </repository>
        <repository>
            <id>org.jboss.repository.releases</id>       
            <name>JBoss Maven Release Repository</name>
            <url>http://repository.jboss.org/nexus/content/repositories/releases</url>
        </repository>
        <repository>
            <id>spring-releases</id>
            <name>Spring Releases</name>
            <url>https://repo.spring.io/libs-release</url>  
        </repository>
        


    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <name>Spring Releases</name>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>

</project>

由于某种原因,我在我的 lib 文件夹中找到了以下 jar log4j-1.2.14.jar。我想从我的最后一场战争中排除这个 jar,所以我尝试了 mvn dependency:tree 但我找不到父依赖项。

我还尝试从 Eclipse 打开 Dependency Hierarchy,但我也找不到这个 jar。如何排除这个 jar?

【问题讨论】:

  • 从您的配置来看,您的项目有一个lib 目录,并且该目录的内容被复制到WEB-INF/lib。不知道你为什么要这样做,但这可能就是罐子所在的地方
  • 感谢您的回答,这确实是问题所在,这是一个旧项目,我不认为问题可能来自那里,您能否将此评论作为答案发布,以便我可以标记为正确答案

标签: java spring-boot maven log4j maven-3


【解决方案1】:

具有另一个具有 provided 范围的依赖项的依赖项不会导致 provided 依赖项位于类路径上。可能是因为测试或构建需要它。

所以你应该做的是检查你的最终部署单元(你自己的 jar/war)并检查 jar 是否在 lib 目录中。如果是其他东西正在管理/包括该依赖关系。 (您可以使用mvn dependency:tree 来确定是哪一个)。

有关 Maven 范围的更多信息,请查看this。如何在 Spring Boot 中包含特定版本的 Log4j2(当您使用它时)在 this Spring.io blog-post 中进行了描述。

【讨论】:

    猜你喜欢
    • 2020-08-14
    • 2017-01-02
    • 1970-01-01
    • 2020-09-21
    • 2019-10-24
    • 2020-11-20
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    相关资源
    最近更新 更多