1

I tried to run the sample code shown here but it's complaining that SLF4J is missing, so I downloaded the zip archive from the official website.

The tutorial video shows that 3 of the jar files are used (log4j-over-slf4j, slf4j-api & slf4j-log4j12) but if I add all 3 of them to the build path of my project (I'm not using Maven!), it complains that both "log4j-over..." and the api are there.

If I get rid of the "over" file, it says "Failed to instantiate SLF4J LoggerFactory".

So, which jar files do I need exactly to stop the complaints and run the sample code?

Neph
  • 1,823
  • 2
  • 31
  • 69
  • 1
    try this https://developers.itextpdf.com/content/itext-7-jump-start-tutorial/installing-itext-7 – arthur Mar 21 '18 at 15:41
  • @arthur can you turn that into an answer and copy the relevant parts of that link? Then your answer can be upvoted and accepted. – Amedee Van Gasse Mar 21 '18 at 15:42
  • 1
    @Neph it becomes a lot easier if you do not manually download jar files (which leads to dependency hell) but use automatic dependency resolution with a build tool like Maven or Gradle or... The website that Arthur linked, explains you how to do that. – Amedee Van Gasse Mar 21 '18 at 15:44
  • @AmedeeVanGasse ok, thanks !! – arthur Mar 21 '18 at 15:44
  • @Neph I know that you write that you don't use Maven. The solution to your problem is: use Maven. – Amedee Van Gasse Mar 21 '18 at 15:47
  • @Amedee Van Gasse I said that I don't use Maven, so linking something that requires you to use it is not a solution for me. My question is simply: "Which jars do I need?", so please stay stay on topic. – Neph Mar 22 '18 at 09:38
  • I tried to explain why using Maven is easier. I really don't know the entire dependency tree. You can find it out yourself: make a small Maven project, it doesn't have to contain any code, just the dependencies. Then you run `mvn dependency:tree`. The output of that command gives you exactly the information you need, which you can then use in your non-Maven project. – Amedee Van Gasse Mar 22 '18 at 10:25
  • @Amedee Van Gasse I'm working on a tiny project, for which installing (and having to deal with) Maven is just overkill. Plus, why set up an extra thing if I can just drag the extra libraries into my project, which usually takes less than a minute. – Neph Mar 22 '18 at 10:33
  • I have explained you how you can find the information. I can now either copy/paste the output on my console and which may be incomplete for you because you have not given enough information, or you can run the command yourself. The output is in the format `groupId:artifactId:jar:version:scope`, which is exactly the information you need to hunt down those jars on search.maven.org, where you can then download those third-party dependencies. – Amedee Van Gasse Mar 22 '18 at 10:50

3 Answers3

2

There is a tutorial showing all the dependencies needed for the sample code. Try this please: https://developers.itextpdf.com/content/itext-7-jump-start-tutorial/installing-itext-7

It basically gives you a list of the exact maven dependencies your project will need to run. You'll also find some indications how to make it work with the IDE like eclipse, netbeans and intelliJ

By using

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

Edit:

you could manually download these 3 dependencies. They get any slf4j with log4j project going:

if you don't trust 3rd party site go the slf4j site and the log4j homepage.

We simply need the slf4j api, its log4j implementation and log4j itself.

arthur
  • 3,245
  • 4
  • 25
  • 34
  • can you add just a tad bit more detail to your answer? That'd be great! – Amedee Van Gasse Mar 21 '18 at 15:45
  • I already saw this website, it's the same one that also links to the video the link of which I posted in my first post. The problem is: If I don't know which jars to use, adding dependencies won't help me either. So unfortunately you ignored my question and the hint that I don't use Maven, which your answer requires to work. – Neph Mar 22 '18 at 09:36
  • if you aren't using maven, then just try download these 3 dependencies mentioned in my edit. it should get your logging part started. – arthur Mar 22 '18 at 09:39
  • There's no "log4j-version" in the zip file, only "log4j-over-slf4j-version" and I already tried it with that one but failed (see my first post).. – Neph Mar 22 '18 at 09:44
  • did you follow the links of the dependencies ? – arthur Mar 22 '18 at 09:46
  • Sorry, I don't download stuff from 3rd party websites. Are there compatibility issues between the different versions? My current slf4j files are version 1.7.25 but I can get 1.6.1 too if the newer ones don't work with log4j (I'm guessing, apache log4j?, version 1.2.16 was released in 2016 though...). – Neph Mar 22 '18 at 09:53
  • 2
    The versions don't really matter, nor where you do you get them. We only need 3 things here: the `slf4j api`, the api-implementation for log4j (`slf4j-log4j12.x.x.x.jar`)and log4j itself (`log4j12.x.x.xx.jar`). Since you don't download from third party, I can refer you to the slf4j and log4 site site I linked in the answer. – arthur Mar 22 '18 at 10:03
  • Thanks, I got log4j from the official website now too (the version from 2016) and it works! :) log4j-1.2.16 seems to be compatible with both version 1.6.1 and the most recent version (1.7.25) of slf4j. I also tried a mix of slf4j 1.7.25 and log4j 2.11.0, so the latest version of both - you apparently need the api and core file with log4j then - but that gave me the "Failed to instantiate SLF4J LoggerFactory" error again. A mix of old and new versions it is then. – Neph Mar 22 '18 at 10:29
  • @Neph happy to see it work for you :). If I was a help to you, would consider accepting my answer above ?? it would be nice. thanks – arthur Mar 22 '18 at 10:47
  • Freaking jar explosion. – Sean Anderson Mar 11 '22 at 19:47
  • Link is broken. Downvoted. – Sean Anderson Mar 11 '22 at 22:57
1

Try removing log4j12. You cannot use both over and log4j12 at the same time. link

CInvt
  • 133
  • 8
  • Please read my first post again, I already tried that and posted the result in the 3rd paragraph. – Neph Mar 22 '18 at 09:56
0

If you wish to use log4j 1.2.x as the logging back-end with slf4j, you need log4j-1.2.17.jar, slf4j-api-1.7.25.jar and slf4j-log4j12-1.7.25.jar.

Ceki
  • 26,753
  • 7
  • 62
  • 71