[Library]: Adding Library Into Java[TM] Project

“currently, i develop an application under Java platform, and i need to use a class which i’ve never used before, where can i get the library which contains the class?”

“how to add more library into my Java project [or program]?”

that questions rise when someone realize that his program needs an additional libraries. there are a sequence of problem people used to face on:

  1. what library does my program needs?
  2. i know the library but where can i get it [or download it]?
  3. i have the library but how to add it into my program?

most of people are getting stuck to find out what kind of library does his program requires to run, the easiest way to find it out is by forcing the program to run, then an exception will be thrown and you just need to see what is missing…? for example, see the following exception:

Exception [TOPLINK-4003] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Exception Description: Configuration error.  Class [com.mysql.jdbc.Driver] not found.
 at oracle.toplink.essentials.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:101)
 at oracle.toplink.essentials.sessions.DefaultConnector.loadDriver(DefaultConnector.java:183)
 at oracle.toplink.essentials.sessions.DefaultConnector.connect(DefaultConnector.java:98)

that’s because of missing class com.mysql.jdbc.Driver, then check this one:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Message
 at javamail.Main.main(Main.java:8)
Caused by: java.lang.ClassNotFoundException: javax.mail.Message
 at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
 at java.security.AccessController.doPrivileged(Native Method)

it’s caused by the missing of class javax.mail.Message, then “how to know the library [jar file] if i just know the required class?” simply open your browser and go to http://findjar.com/ to seach what jar file contains the class. download it.

now you have the jar, so how to connect the library [jar file] to the program? there are two possibilities, your program written with IDE or NOT at all.

if you use an IDE in develop your program you just need to add it on, in NetBeans IDE for example you just need to do these:

  1. right click on the project then select properties,
  2. go to ‘Libraries’ category,
  3. select ‘Add JAR/Folder’ to find you JAR file.

but if you don’t use any IDE, you have to link the JAR to the ‘Environtment Variables’, i will show how to add it in Windows operating system.

  1. first ensure the JAR file is in your local drive, then right click on the My Computer icon > select Properties
  2. select the Advanced tab > select Environtment Variables
  3. find the ‘Path’ variable and edit it to add your jar directory location
  4. finish. reopen your command prompt [if you use it].

have a good day,…


One thought on “[Library]: Adding Library Into Java[TM] Project

  1. Pingback: [Exception]: a database exception [part 1] « mariosimaremare

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s