File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Where to put jar files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Where to put jar files" Watch "Where to put jar files" New topic

Where to put jar files

Andrew Cleland

Joined: Apr 13, 2005
Posts: 4
I have just started with Java, using 1.4.2, in windows. I have a couple of questions about where 3rd party jar files should be placed.

I am using iText, a set of java classes to create PDF files. Now to get my programs to compile, I placed the itext-1.3.jar file in the same folder as my java source file. Now I know that is definitely not the place to really put it. Should I create a seperate folder solely for itext, or do I put the jar file under the jre folder under the j2sdk folder, or some other place.

2nd Question: To get my java code to compile, I copied servlet.jar to my local folder, as it does not seem to be in the jre path. Is servlet.jar part of j2SDK1.4.2, and I just wasn't setting it up correctly. Or did I have to download it, and where should it be placed, in which folder?

Thank you

Joel McNary

Joined: Aug 20, 2001
Posts: 1824

I create a lib folder and place my .jars in there. (C:\user\java\lib\ is where mine is...) Then, I set the CLASSPATH to include the .jars in that directory. (Note that you have to specify each .jar explicitely in the CLASSPATH; specifying the lib directory is not sufficient.)

As far as your second questions, no, servlet.jar is not part of the J2SDK -- it's part of the J2EESDK. If you need to use it in a non-J2EE application, then yes, you need to include it manually.

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Some people like to put their jar files in C:\java\jre\lib\ext

jar files in there are automatically added to the classpath.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Not sure what you're using for development in terms of IDE. Assuming you are using and IDE this is what I do.

Create a lib directory inside the project directory, by sructure looks like:

In the lib directory goes the jar I'm using, if a jar requires other jars I create a subdir for that (just for me to keep things straight in case I want to add/remove/change something).

During development let the IDE handle the classpath issues for compilation. When you get ready to release create a manifest file setting all the jars in the lib directory. When you do a release you can create a jar from source and put it and the lib directory into a zip. The user then only has to unzip and doubleclick the jar. Of course there are more elegant, though more difficult, installation methods.

If you are using a text editor dealing with the classpath becomes more tedious.

I tend to stay away from putting jars into the java\jre\lib\ext folder. It keep me from running into the problem of 'works on my dev machine, but not anywhere else'.
I agree. Here's the link:
subject: Where to put jar files
It's not a secret anymore!