Posts Tagged ‘Java’

ABC to Import a jar file in Netbeans 6.5

June 17, 2009

If you want to import a jar file in NetBeans, I guess I can help you out. Using the following procedure, you can import folders as well as other projects to the project you desire. I wanted to use the log4j for using logger in my application. So I had to import a jar file (log4j-1.2.15.jar) to the project. One of my friends helped me out, infact both of us just discovered how to import. Here we go…

I always feel that a picture can convey 1000 words, so the snaps. The following is what I did:

Right click on the project to which you which to import files. Note that the project need not be set as a Main project to import packages into it.

.Right Click on the Project Name !

Right Click on the Project Name !

In the window that opens, Choose Libraries in the left panel as shown below. On the right hand side of the window, I hope,  you can see an option called ‘Add JAR/Folder‘, click on that.

Select Libraries from the Left Panel !

Select Libraries from the Left Panel !

The new window that opens in familiar, I guess. Well, then Browse to the place where you have the jar file, select it and press ‘Open

Select the jar file you want to import

Select the jar file you want to import

As shown below, in a tab called ‘Compile‘, you can see the files that you have added (This is the default chosen tab, so after you have pressed ‘Open‘ in the previous step you will land here). Repeat the process if you want to add more files and then press ‘OK‘.

Click on Ok after you have imported

Click on Ok after you have imported

Another windows opens and you can see that the things you have added get saved (This is what the window shows :), it is just to see, nothing needs to be done).

The filed you have imported are saved

The filed you have imported are saved

As said earlier, the same procedure can be applied to add folders and other projects. If you had noticed, those where the other option in the image 2 shown above. Problems are Welcome  ! 😀

Types of Log Appenders in log4j

June 3, 2009

Types of log appender

An appender specifies where your log messages are written to. There is a wide choice of appenders available. All appenders are direct or indirect subclasses of the AppenderSkeleton. Therefore we can find all options on the following API page:

The console and the file appender are a subclass of WriterAppender.

Later on, we are going to choose examples for the following appenders.

ConsoleAppender Logs to console
FileAppender Logs to a file
SMTPAppender Logs by email
RollingFileAppender Logs to a file, starts a new file once the max size is reached. (An alternative is the DailyRollingFileAppender which creates on file per day)

But there are as well:

AsyncAppender, JDBCAppender, JMSAppender, LF5Appender, NTEventLogAppender, NullAppender, NullAppender, SMTPAppender, SocketAppender, SocketHubAppender, SyslogAppender, TelnetAppender, DailyRollingFileAppender, RollingFileAppender.

Custom appenders can be created as well. The log4j download comes with a whole bunch of samples in the examples directory.

For more information on log4j, visit the source below.

Source :

Download and Install log4j / Log for Java

May 1, 2009

Log for java aka log4j is a library. Its a small software that need to be downloaded an installed. The installation which I am going to illustrate if for Linux and a similar procedure can be followed for windows. It can be downloaded from the following link –

Download the tar file and extract it using the following command

tar -xvvzf apache-log4j-1.2.15.tar.gz

Move the for apache-log4j-1.2.15 to the a location of your choice. But I recommend you to put it in a folder where you have installed java (say you have moved the extracted the folder to /usr/java/). Now, the jar file log4j is inside the folder. The path should be


After this there are two ways to make it recogniseable by you java program. One is you need to set the CLASSPATH. The second and the best alternative is, you could import that jar file. I guess most of you use NetBeans or Eclipse for java programming. So all you need to do is to imort this jar file and it will be recognised by you package. If you want to know how to use logger function, read the following manual

%d bloggers like this: