LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 02-22-2009, 08:22 AM   #1
preeti_c
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 HelloWorld.java

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

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 java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: HelloWorld. Program will exit.

Could someone please tell me what is wrong?
 
Old 02-22-2009, 08:27 AM   #2
jay73
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, 10:41 AM   #3
preeti_c
LQ Newbie
 
Registered: Feb 2009
Posts: 5

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


Reply


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 04:31 AM
External Directory As Classpath in eclipse MRMadhav Programming 8 05-09-2006 03:13 AM
Fedora Core 1 Associating .jar files with java -jar command pymehta Fedora 0 01-13-2005 05:26 AM
Permission Denied while installing new jar library for my new application lavinal Linux - Software 1 09-02-2004 04:47 AM
How to make executetable jar file? if not setting the classpath? antony_csf General 1 07-01-2004 03:11 AM


All times are GMT -5. The time now is 07:48 PM.

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