Search code examples
javaeclipseeclipse-rcptycho

How to solve SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" in Eclipse Tycho RCP


I'm using Eclipse 2022-03.

I got two types of error messages after an update of a third party library.

1) Missing contraints

This type of error I solved by 'Add required plug-ins' in the Run and Debug configurations. The plug-in org.slf4j.api (1.7.30.v20200204-2150) solved the problem. Unfortunately I have to do 'Add required plug-ins' each time I start up Eclipse.

Any idea how I can get 'Add required plug-ins' to stick between restarts of Eclipse?

2) SLF4J: Failed to load class

Same error occurs for my headless build: enter image description here

What is the way to solve the classic error message "SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"" in a Eclipse Tycho RCP project?

According to http://www.slf4j.org/codes.html#StaticLoggerBinder I need to download an implementation (JAR file) of the slf4j-api and put it in the classpath.

a) Where can I find a typical slf4j-api implementation to use in my project?

b) Where shall integrate that API implementation (JAR file) in my Eclipse Tycho RCP project so it works both for head and headless builds?

My Eclipse RCP Tycho project is using a target-platform definition:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target name="target-platform" sequenceNumber="1">
    <locations>
        <location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
            <repository location="http://download.eclipse.org/eclipse/updates/4.23"/>
            <unit id="org.eclipse.equinox.sdk.feature.group" version="3.23.300.v20220223-1131"/>
            <unit id="org.eclipse.platform.ide" version="4.23.0.I20220308-0310"/>
            <unit id="org.eclipse.platform.sdk" version="4.23.0.I20220308-0310"/>
        </location>
        <location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
            <repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20220302172233/repository"/>
            <unit id="org.junit" version="4.13.2.v20211018-1956"/>
            <unit id="org.junit.jupiter.api" version="5.8.1.v20211018-1956"/>
            <unit id="org.junit.jupiter.engine" version="5.8.1.v20211018-1956"/>
            <unit id="org.slf4j.binding.simple" version="1.7.30.v20200204-2150"/>
            <unit id="org.slf4j.binding.simple.source" version="1.7.30.v20200204-2150"/>
        </location>
        <location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
            <repository location="https://download.eclipse.org/nattable/releases/2.0.2/repository/"/>
            <unit id="org.eclipse.nebula.widgets.nattable.core.feature.feature.group" version="2.0.2.202111300816"/>
            <unit id="org.eclipse.nebula.widgets.nattable.extension.e4.feature.feature.group" version="2.0.2.202111300816"/>
            <unit id="org.eclipse.nebula.widgets.nattable.extension.glazedlists.feature.feature.group" version="2.0.2.202111300816"/>
        </location>
        <location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
            <repository location="https://download.eclipse.org/justj/jres/17/updates/release/17.0.2"/>
            <unit id="org.eclipse.justj.openjdk.hotspot.jre.full.feature.group" version="17.0.2.v20220201-1208"/>
        </location>
    </locations>
</target>

This is my POM:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>vcs</groupId>
    <artifactId>vcs.root</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <properties>
        <tycho.version>2.7.1</tycho.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-p2-director-plugin</artifactId>
                <version>${tycho.version}</version>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-maven-plugin</artifactId>
                <version>${tycho.version}</version>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-toolchains-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>toolchain</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <toolchains>
                        <jdk>
                            <version>17.0.2</version>
                            <vendor>Eclipse Adoptium</vendor>
                        </jdk>
                        <jdk>
                            <version>11.0.15</version>
                            <vendor>Eclipse Adoptium</vendor>
                        </jdk>
                        <jdk>
                            <version>18.0.1</version>
                            <vendor>Eclipse Adoptium</vendor>
                        </jdk>
                    </toolchains>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>target-platform-configuration</artifactId>
                <version>${tycho.version}</version>
                <configuration>
                    <executionEnvironment>org.eclipse.justj.openjdk.hotspot.jre.full-17</executionEnvironment>
                    <target>
                        <artifact>
                            <groupId>vcs</groupId>
                            <artifactId>target-platform</artifactId>
                            <version>0.0.1-SNAPSHOT</version>
                        </artifact>
                    </target>
                    <environments>
                        <environment>
                            <os>win32</os>
                            <ws>win32</ws>
                            <arch>x86_64</arch>
                        </environment>
                    </environments>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <modules>
        <module>bundles</module>
        <module>features</module>
        <module>releng</module>
        <module>tests</module>
    </modules>
</project>

Here is the list of installed software in Eclipse: Installed software

Here is my product definition:

<?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?>

<product name="ReqTool" uid="reqtool" id="info.wallberg.reqtool.userinterface.plugin.product" application="org.eclipse.e4.ui.workbench.swt.E4Application" version="0.0.1" useFeatures="true" includeLaunchers="true">

   <configIni use="default">
   </configIni>

   <launcherArgs>
      <programArgs>-clearPersistedState
-console
      </programArgs>
      <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts
      </vmArgsMac>
   </launcherArgs>

   <windowImages/>

   <launcher>
      <win useIco="false">
         <bmp/>
      </win>
   </launcher>

   <vm>
   </vm>

   <plugins>
   </plugins>

   <features>
      <feature id="info.wallberg.library.jre.win32.x86_64"/>
      <feature id="info.wallberg.library.fileextractor.feature"/>
      <feature id="info.wallberg.library.oscommand.feature"/>
      <feature id="info.wallberg.library.pdfextractor.feature"/>
      <feature id="info.wallberg.reqtool.requirementmodel.feature"/>
      <feature id="info.wallberg.reqtool.requirementservice.cursorial.feature"/>
      <feature id="info.wallberg.reqtool.userinterface.feature"/>
      <feature id="org.eclipse.e4.rcp" installMode="root"/>
      <feature id="org.eclipse.emf.ecore" installMode="root"/>
      <feature id="org.eclipse.emf.common" installMode="root"/>
      <feature id="org.eclipse.nebula.widgets.nattable.core.feature" installMode="root"/>
      <feature id="org.eclipse.nebula.widgets.nattable.extension.glazedlists.feature" installMode="root"/>
   </features>

   <configurations>
      <plugin id="org.apache.felix.scr" autoStart="true" startLevel="2" />
      <plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="0" />
      <plugin id="org.eclipse.equinox.common" autoStart="true" startLevel="2" />
      <plugin id="org.eclipse.equinox.event" autoStart="true" startLevel="2" />
      <plugin id="org.eclipse.equinox.simpleconfigurator" autoStart="true" startLevel="1" />
   </configurations>

   <preferencesInfo>
      <targetfile overwrite="false"/>
   </preferencesInfo>

   <cssInfo>
      <file path="/info.wallberg.reqtool.userinterface.plugin/css/default.css"/>
   </cssInfo>

</product>

Solution

  • That depends on how you want to add logging support to your application. If you don't care about logging you can either ignore the warning or add the nop logger or simple logger from eclipse Orbit. The NatTable examples are using the simple binding for example. The target definition consumes the SLF4J binding from Orbit, the E4 example feature includes the bundle.