javamavenslf4jrenjin

Using renjin with a different slf4j implementation


I'm using renjin in a Java web application to load RData files. Since I'm in a corporate network i only have access to packages from maven central. Since renjin is hosted in a different repository i downloaded the standalone jar (renjin-script-engine-3.5-beta43.jar) from the website and manually installed it in my local maven repository. The integration with Java works fine.

I'm using slf4j (1.7.28) in my application as the main logging api. However, when i try to add log4j2 (2.12.1) as the logging implementation to use, i get a slf4j warning upon startup due to multiple implementations on the classpath:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:<project-path>/target/<project-name>-0.0.1-SNAPSHOT/WEB-INF/lib/log4j-slf4j-impl-2.12.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:<project-path>/target/<project-name>-0.0.1-SNAPSHOT/WEB-INF/lib/renjin-script-engine-3.5-beta43.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

It seems renjin includes a slf4j implementation at compile time, which is something slf4j recommends against. Since the implementation isn't added as a transitive dependency, i can't exclude it in maven.

The slf4j documentation says it should mention which implementation it binds against, but i don't have any output in that regard. My current log4j2.xml configuration seems to have no effect on the log output i see, but i don't know if that is due to a problem in the configuration or because slf4j binds against the other implementation. To properly debug this i would like to fix the slf4j warning and have only log4j2 as an implementation on the classpath. I also looked at compiling renjin myself but it requires an old gcc version (4.7) which i can't install ony my machine (Ubuntu 18.04.3). In addition some of the build dependencies are located on other repositories, which i can't access due to network restrictions.

The newest renjin jar (beta73) also includes the slf4j implementation classes mentioned. Is this an issue i should bring up on the renjin github page, or is there some other way i can use renjin without the included slf4j implementation?

For reference, this is my current pom.xml (i have replaced the project name, groupId and artifactId with generic placeholders):

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId><my-group></groupId>
<artifactId><my-project></artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name><project-name></name>
<description>Backend for LDB</description>

<properties>
    <java.version>11</java.version>
    <ignite.version>2.7.6</ignite.version>
    <!-- Springboot will default to 1.4.199, which will not work with ignite. -->
    <h2.version>1.4.197</h2.version>
    <log4j2.version>2.12.1</log4j2.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.renjin</groupId>
        <artifactId>renjin-script-engine</artifactId>
        <version>RELEASE</version>
    </dependency>
    <dependency>
        <groupId>de.grundid.opendatalab</groupId>
        <artifactId>geojson-jackson</artifactId>
        <version>1.8.1</version>
    </dependency>
    <!--
        The swagger libraries included in springfox contain a bug that will log various NumberFormatExceptions due to not set example values
        in ApiModelProperty, when rendering the Swagger UI. To fix this we load a newer version of these swagger libraries.
        See: https://github.com/springfox/springfox/issues/2265#issuecomment-413286451
     -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.2</version>
        <exclusions>
            <exclusion>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-annotations</artifactId>
            </exclusion>
            <exclusion>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-models</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-annotations</artifactId>
        <version>1.5.23</version>
    </dependency>
    <dependency>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-models</artifactId>
        <version>1.5.23</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.2</version>
    </dependency>
    <!-- Apache Ignite -->
    <dependency>
        <groupId>org.apache.ignite</groupId>
        <artifactId>ignite-core</artifactId>
        <version>${ignite.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.ignite</groupId>
        <artifactId>ignite-spring</artifactId>
        <version>${ignite.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.ignite</groupId>
        <artifactId>ignite-indexing</artifactId>
        <version>${ignite.version}</version>
    </dependency>
    <!-- Logging Slf4j with log4j2 as the implementation -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>${log4j2.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>${log4j2.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>${log4j2.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-web</artifactId>
        <version>${log4j2.version}</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>


Solution

  • It sounds like you've downloaded the renjin-script-engine-3.5-beta43-jar-with-dependencies.jar.

    This distribution does include all of Renjin's dependencies, and is intended for those who are not using Maven or another build tool.

    If you're unable to use Renjin's repository, you'd have to install the "normal" renjin-script-engine.jar and its pom file into your local maven repository, along with all of its dependencies, some of which are only available from our repository.

    You can start here: https://nexus.bedatadriven.com/content/groups/public/org/renjin/renjin-script-engine/3.5-beta76/

    But it will be alot of manual work.

    Can I ask what is preventing you from accessing the repository? The jar you downloaded is also hosted in our repository, so it doesn't sound like a firewall issue...