I am working through Tim Downey's book "Web Development with Java".
In chapter 4 one of the topics is logging with log4j.
In order to initialise the logger an initialisation servlet is used.
One of the classes needed is, e.g., "FileAppender". Hence, there is an import statement at the top of the file for it:
import org.apache.log4j.FileAppender;
I also used the same import statement. However, netbeans is telling me that this class doesn't exist. (The same is true for any other class from the log4j library.)
Normally, when I create an object of a class I have not yet imported, the netbeans IDE offers me to import the respective class.
So I created an object of type "FileAppender":
FileAppender appender = getAppender(logPath);
... I hoped that the IDE would tell me what import-statement to use in order to import this class.
However, no such luck. Apparently, the IDE does not know about such a class.
So, I think that for some reason the IDE does not know where to look. This again means that I probably did something wrong when setting log4j up.
Here's what I did:
But the IDE doesn't seem to know about any log4j packages or classes.
Did I do anything wrong? (What did I do wrong?)
************************UPDATE***************************************
Here's a screenshot of the netbeans library folder after I added log4j:
Here's a picture of the IDE telling me it doesn't know about log4j's package (What you see is the upper part of the file "InitLog4j.java", which again is inside the package named "various". Package "various" is inside the folder named "Source Packages"):
***********************UPDATE2***************************************
The problem exists independent of whether I include log4j as library or as JAR/FOLDER.
After adding log4j as Jar/Folder:
... my netbeans folder structure looks as follows (log4j is in the folder whose path starts with "/Users"):
However, the problem remains the same. Netbeans doesn't know about log4j packages.
**********************UPDATE3***********************************
I found the FileAppender class among the many files inside the log4j folder:
So, the class "FileAppender" exists. Hence, when I create an object of type "FileAppender", the Idea should offer to import the class. However, this does not happen (in the screenshot above you can see that the class "FileAppender" exists (see left side), you can also see that the IDE does not recognise the class (see code on the right side)).
*************************UPDATE4***********************************
Instead of adding the whole folder, I now only added the jar files inside the folder. The netbeans folder structure now looks as follows:
However, the IDE still does not seem to recognise the log4j packages (e.g. for the FileAppender object no import statement is suggested).
As per your screenshot. It seems like you have added this jar as library. You need to add the jar using Add Jar/Folder..
option not the Add Library..
It will prompt window to navigate and select your jar.
Once, you add them, then it should look like
You can expand the jar from here and see, if required class exists inside the jar or not.
==Update==
You need to select only *.jar
file not the complete folder. As shown below.