0

I am working on a Maven-based Web Application that is running on Tomcat. I am trying to add the log4j2 dependency to my maven project. However when I try to build my project the error at the bottom occurs. I tried to install the log4j dependency locally, however I couldn't get it to work neither. I wanted to reinstall Maven, but somehow I can only deactivate it. If you need more Information please tell me so I can provide it.

Output when I try to build the project:

cd C:\...\Blockchain; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_161" cmd /c "\"\"C:\\Program Files\\NetBeans 8.2\\java\\maven\\bin\\mvn.bat\" -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.2\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 install\""
Scanning for projects...

------------------------------------------------------------------------
Building Blockchain 1.0-SNAPSHOT
------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/apache/log4j-core/2.13.0/log4j-core-2.13.0.pom

------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 2.069s
Finished at: Mon May 11 21:50:01 CEST 2020
Final Memory: 8M/123M
------------------------------------------------------------------------
Failed to execute goal on project Blockchain: Could not resolve dependencies for project com.bowolfcoin:Blockchain:war:1.0-SNAPSHOT: Failed to collect dependencies for [com.owlike:genson:jar:1.5 (compile), org.apache:log4j-core:jar:2.13.0 (compile), javax:javaee-web-api:jar:7.0 (provided), org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.23 (compile), org.apache.tomcat:tomcat-jasper:jar:8.5.23 (compile), org.glassfish.jersey.containers:jersey-container-servlet:jar:2.0 (compile), org.bouncycastle:bcpkix-jdk15on:jar:1.56 (compile)]: Failed to read artifact descriptor for org.apache:log4j-core:jar:2.13.0: Could not transfer artifact org.apache:log4j-core:pom:2.13.0 from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/apache/log4j-core/2.13.0/log4j-core-2.13.0.pom. Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

Here is the full pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.bowolfcoin</groupId>
    <artifactId>Blockchain</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>Blockchain</name>

    <properties>
        <tomcat.version>8.5.23</tomcat.version>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.owlike</groupId>
            <artifactId>genson</artifactId>
            <version>1.5</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.apache</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.13.0</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-core</artifactId>
            <version>${tomcat.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jasper</artifactId>
            <version>${tomcat.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcpkix-jdk15on</artifactId>
            <version>1.56</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

I was able to build the project now. However I get the following error when I try to create a Logger object. In the following code, the getLogger() function is underlined red with the following error text:

Code:

package com.blockchain.api.services;

import com.blockchain.logic.DependencyManager;
import com.blockchain.logic.PendingTransactions;
import com.blockchain.models.Block;
import com.blockchain.models.Transaction;
import com.blockchain.utils.SHA3Helper;
import org.apache.logging.log4j.core.Logger;


import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

/**
 *
 * @author Bongi
 */

@Path("transactions")
public class TransactionService {

    private static Logger logger = Logger.getLogger(Transaction.class);

Error

cannot find symbol
  symbol:   method getLogger(Class<Transaction>)
  location: class Logger
Bongni
  • 118
  • 2
  • 9
  • I had similar issues. I had to exclude some libs for a couple of dependencies. Gradle config but perhaps it will help compile(group: 'commons-logging', name: 'commons-logging-api', version: '1.1') { exclude(module: 'servlet-api') } compile (group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.2.0') { exclude(module: 'commons-logging') } – Evgeniy May 11 '20 at 20:08
  • 2
    You try to download with http from a repository, but you need https. Have you added a repository tag in your pom or settings? – Christian May 11 '20 at 20:14
  • 2
    You have to use https instead of http .... has been changed https://blog.sonatype.com/central-repository-moving-to-https – khmarbaise May 11 '20 at 20:56
  • Add your full `pom.xml` file to check on repository and dependency tags. If this has a parent pom, check on its repositories as well. – Nipun Thathsara May 12 '20 at 16:12
  • @Christian I haven't yet added repository tags. However when I try to add them, the project still tries to download the dependencies from the same address. – Bongni May 14 '20 at 15:48
  • @Bowolf I tried your pom.xml and found the issue - see answer below:-) – Christian May 14 '20 at 18:42
  • @Christian Thank's for your answer, I tried it and it worked. I was able to build the project. However the library still doesn't work. The new error is added to the question. – Bongni May 20 '20 at 11:29
  • @Bowolf Thanks for the feedback. Usually, you don't extend questions with new questions once answered. I would recommend you to create a new question due to visiblity. Also, this one has been closed (unjustified if you ask me). Could you also accept my correct answer then? Regarding your issue, you may not have Logger on your IDE classpath. If using Eclipse, it might be worth to "reimport as Maven project" – Christian May 21 '20 at 10:10
  • @Christian Thanks for the info, I accepted your answer and will try your recommendation. – Bongni May 21 '20 at 15:57

1 Answers1

2

Your logging artifact seems to be incorrect. Can you try this:

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

You can confirm this path here: https://repo.maven.apache.org/maven2/org/apache/logging/log4j/log4j-core/2.13.0/

Also see: https://logging.apache.org/log4j/2.x/maven-artifacts.html

Christian
  • 7,062
  • 5
  • 36
  • 39