Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-22-2009, 09:22 AM   #1
LQ Newbie
Registered: Feb 2009
Posts: 5

Rep: Reputation: 0
classpath for external jar library

Hey all

I have to use an external library itext-1.4.5.jar located at /usr/share/java in a program

I had compiled the program as
$javac -classpath /usr/share/java/itext-1.4.5.jar

and it compiled properly

But I dont know how to run it.

If I give

$java -classpath /usr/share/java/itext-1.4.5.jar HelloWorld

I get these errors

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
Could not find the main class: HelloWorld. Program will exit.

Could someone please tell me what is wrong?
Old 02-22-2009, 09:27 AM   #2
LQ Guru
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
Yes, you are overriding the default classpath; as a consequence, javac does not look in the current working directory so it does not find your classfile. Use -cp .;/usr/share/etc. instead
Old 02-22-2009, 11:41 AM   #3
LQ Newbie
Registered: Feb 2009
Posts: 5

Original Poster
Rep: Reputation: 0
It worked.Thank you


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ant for tomcat5 on FC5, problems with classpath/jar files rhoekstra Programming 0 05-24-2006 05:31 AM
External Directory As Classpath in eclipse MRMadhav Programming 8 05-09-2006 04:13 AM
Fedora Core 1 Associating .jar files with java -jar command pymehta Fedora 0 01-13-2005 06:26 AM
Permission Denied while installing new jar library for my new application lavinal Linux - Software 1 09-02-2004 05:47 AM
How to make executetable jar file? if not setting the classpath? antony_csf General 1 07-01-2004 04:11 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:51 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration