Take the 2-minute tour ×

I have just downloaded a third party java library which i need for a program i'm about to create.

But i can't figure out how to actually install the library so that i can literally type

import path.to.library;

in my java class file without having any errors.

I have looked at many tutorials and answers on StackOverflow but each of them seems to include the use of some or the other IDEs for java.

Well, i'm a bit rustic and would like to know how to make it work with notepad and the command line, coz that's what i use to make a program.

share|improve this question
What IDE are you using? You need to add your library to your class path. Every IDEs has a different way to do this. –  Edwin Dalorzo Oct 15 '12 at 14:35
There's no "install" step in using a jar file. Just make sure that it's on your classpath (either specified via the -cp switch of java/javac or in the CLASSPATH variable, I suggest the first option). –  Joachim Sauer Oct 15 '12 at 14:35
"write it work with notepad" Heck that is rustic, if you mean the Windows Notepad. Not even the 'code formatting' of a simple (non IDE) editor like TextPad! –  Andrew Thompson Oct 15 '12 at 14:38
"Well, i'm a bit rustic" ... that's the best one I've seen all day :-) –  Stephen C Oct 15 '12 at 14:45

6 Answers 6

up vote 1 down vote accepted

When you are compiling, include the following in your line:

-classpath nameOfJar.jar

However, once you actually switch to use an IDE, you will see the multiple benefits this approach can bring.

share|improve this answer
thank you, this answer was the only one which helped. Is there a way to put the lib permanently into my computer, so that i dont have to do it with each program i make –  udiboy1209 Oct 15 '12 at 14:43
You can place the lib somewhere and refer it using absolute paths, but that will lack in portability. Please try an IDE: Eclipse, IntelliJ IDEA, NetBeans,... –  Dan Oct 15 '12 at 14:44
can you please tell me how to "place the lib" and refer it –  udiboy1209 Oct 15 '12 at 14:46
Have the lib directory in one place and refer it in the -classpath using absolute paths. However, please try an IDE. –  Dan Oct 15 '12 at 14:55

You don't specify a path in the import statement, just the package name.

All usable JAR files have to be specified in the classpath on commandline when starting your Java program.

share|improve this answer

You need to understand how Java's classpath works. For a comprehensive description, read the Oracle manual page on this topic. Alternatively the PATH and CLASSPATH page of the Java Tutorial.

(FWIW - it is generally considered to be a bad idea to use the CLASSPATH environment variable to set the classpath, because this is liable to lead to "nasty surprises" if you deal with software that requires different classpaths.)

share|improve this answer

If you don't use any IDE you won't have code complete. However if you know all the packages/classes/methods names/signitures you can use pure Notepad and then compile it by adding the library to your classpath (eg. using the -cp switch in the javac command when compiling)

share|improve this answer

JARs are not required to be installed. They required to be accessible at compile- and run- time. You can add jar by command line parameter or CLASSPATH environment variable. IDEs have special means for setting JAR;s location in visual manner.

share|improve this answer

You'll need to be more specific about what you have tried so far. This generally isn't something complex though, if you want to manually invoke the compiler you would do something like

javac -cp somejar.jar myclass

Once you get used to this process, it's better to automate it using a build tool such as ant or maven. Ant is a little easier to begin with, maven has some additional capabilities that make it a little more complex.

share|improve this answer

Your Answer


