52

I'm trying to run the sample tiles example given here.

Below is my POM.xml:

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-api</artifactId>
            <version>2.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-core</artifactId>
            <version>2.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-jsp</artifactId>
            <version>2.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.5.2</version>
        </dependency>

When I'm trying to run the example the below error is thrown:

Sep 17, 2010 11:59:43 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class      org.apache.tiles.web.startup.TilesListener
java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:131)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
at org.apache.tiles.web.startup.TilesListener.<init>(TilesListener.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)

Any idea?

I spent 30 minutes googling for this but could not find a possible sollution.

Please help me...

Tom Jonckheere
  • 1,630
  • 3
  • 20
  • 37
javanoob
  • 6,070
  • 16
  • 65
  • 88
  • when ever you find difficulty with libraries better check with dependency tree and exempt the unwanted libraries! – Mateen May 14 '18 at 01:01

6 Answers6

125

You have included a dependency on the SLF4J API, which is what you use in your application for logging, but you must also include an implementation that does the real logging work.

For example to log through Log4J you would add this dependency:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.2</version>
    </dependency>

The recommended implementation would be logback-classic, which is the successor of Log4j, made by the same guys that made SLF4J and Log4J:

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>0.9.24</version>
</dependency>

Note: The versions may be incorrect.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
gpeche
  • 21,974
  • 5
  • 38
  • 51
  • 7
    To be precise, logback is a fork of log4j, not a successor. – Thorbjørn Ravn Andersen Sep 17 '10 at 18:51
  • 3
    org.slf4j slf4j-log4j12 1.5.2 Added the above dependency and it worked...`Thanks guys for all replies` – javanoob Sep 17 '10 at 18:52
  • 16
    Logback is not a fork of log4j, indeed it's a successor. It doesn't really share code with Log4j and Ceki Gülcü, the creator of both frameworks, has clearly stated that when creating it: http://ceki.blogspot.fr/search?q=logback. – Doc Davluz Nov 16 '12 at 15:33
  • 2
    for gradle: `implementation 'org.slf4j:slf4j-log4j12:1.5.2'` – moolsbytheway May 19 '18 at 00:40
  • I had hoped to allow a technical end user to be able to specify the application logger binding at runtime - rather than declare a logger implementation dependency. But my attempt, based on HelloWorld, using java -cp slf4j-1.6.0 -jar HW.jar did not find org.slf4j.impl.StaticLoggerBinder. It works if I explicitly declare the dependency in the manifest - but I wanted to put it on the command line. – Kirk Bates Oct 22 '18 at 09:22
  • java -cp HW_lib\slf4j-simple-1.6.0.jar -jar HW.jar – Kirk Bates Oct 22 '18 at 09:30
12

You have included the dependency for sflj's api, but not the dependency for the implementation of the api, that is a separate jar, you could try slf4j-simple-1.6.1.jar.

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
  • 2
    That worked for me. I have been using the application on TomCat for years. Tried running on JBoss 5.1.1 and it needed this library. I don't know why it didn't need it on TomCat..... – AgilePro Oct 28 '15 at 12:57
1

Add the all tiles jars like(tiles-jsp,tiles-servlet,tiles-template,tiles-extras.tiles-core ) to your server lib folder and your application build path then it work if you using apache tailes with spring mvc application

alexbt
  • 16,415
  • 6
  • 78
  • 87
1

A good practice to ensure consistency of SL4J versions is to centralize the version in a property like this:

...
    <properties>
        <org.slf4j.version>1.5.2</org.slf4j.version><!-- SLF4J release -->
    </properties>
...
     <dependencies>
        <!-- SL4J with LOG4J implementation -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j.version}</version>
        </dependency>
...
Pmag
  • 125
  • 1
  • 4
0

i had the same error while working with hibernate, i had added below dependency in my pom.xml that solved the problem

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.10</version>
    </dependency>

reference https://mvnrepository.com/artifact/org.slf4j/slf4j-api

Mateen
  • 1,631
  • 1
  • 23
  • 27
  • yes you are right, but changing the dependency version solved the issue for me. op has 1.5.2 i have pasted 1.7.10 – Mateen Oct 22 '19 at 14:34
-1

Copy all order entries of home folder .iml file into your /src/main/main.iml file. This will solve the problem.

Vivek
  • 1