• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Exception in displaying data in a pdf format

 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to display data in a pdf format.
I've downloaded 3 jars & they're put in my jre/lib/ext/ path.
The 3 jars are:
iText-2.1.4.jar
iText-rtf-2.1.4.jar
iText-rups-2.1.4.jar


My path & classpath settings are:


Now this is my code:


When i compile , there is no problem, when I try to run it , it throws java.lang.NoClassDefFoundError.

Please throw some light on this.
Regards.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sun's Java installers used to sometimes (often) put a copy of java.exe into your C:\WINDOWS directory (or someplace along those lines) which is used by the Java Plug-in. This then leads to a situation where your path contains javac.exe from a JDK you've installed, but java.exe in C:\WINDOWS (or maybe in a JRE you've installed that's earlier on your path.)

In any case, examine your system closely; make sure that the java.exe you're running is the one that you expect. If it's not, then it won't be looking in that "ext" directory for extensions.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Hill,


So my java.exe is working fine.
Regards.
 
Sheriff
Posts: 22811
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, please don't call Ernest "Hill". It's not his first name nor his last name - it's part of his last name. If you go around calling people by their last name only (which is quite uncommon in Europe and the US), then at least use "Friedman-Hill". Or just be lazy and call him EFH like everyone else does


Now back to the problem. You may not be using the JRE you think you are. When you install the JDK, it actually installs 2 JREs: one inside the JDK folder (in a folder simply called jre) and one in C:\Program Files (usually). So if you have put them in C:\jdk1.5.0\jre\lib\ext, the other JRE (C:\Program Files\Java\xxxxx) will not see those libraries. You have to copy the files to that folder as well.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ramya narayanan:

So my java.exe is working fine.



I didn't say that it wasn't working.

What I said was that the java.exe you're running may not actually be looking to the JDK extensions directory where you've installed iText.

And actually, I only said "may not" just to be nice, because I will actually guarantee you that what I've described is precisely the problem.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks RP & EFH.
Now after putting all the jar's in both the exts(JRE of program files & in C:\jdk1.5) it's working fine.
If I have the jars simply in my classpath C:\jdk1.5\lib then it was throwing the same error at run time
Why?
Regards.

Note: Dear EFH please excuse me on your name I've used in the last post.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now when I include the jar files in my classpath(C:\jdk1.5\lib) & compile , the program is not getting compiled.
The error trace is:


It shows the some pdf related classes are not found, which is not the case when we include the jar in jre\ext.
Why is this so?

2) But other normal built-in classes are working at runtime.
How?
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not be misusing JDK's /lib folder to place 3rd party JAR's in. It makes your application less portable. You would also get more trouble like as you're struggling with now when you're using multiple JDK's and/or ever going to reinstall or upgrade it.

Just use the -classpath or -cp argument for that.

And to execute it:
To save effort in typing you can easily wrap in a batch or shell file, depending on the OS used.
[ December 19, 2008: Message edited by: Bauke Scholtz ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, I use ANT tasks to keep straight all the various versions of Java and toolkits present on my machine. ANT lets you define "properties" that get substituted into tasks like:


used to compile like:


Yes, this is a bit more work than defining batch files with classpath variables but it is more general and worth the learning curve.

Bill
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bauke Scholtz & William Brogden for their valuable opinions.
Now I've understood

Don't put third party jar in jdk\lib. Instead use
i) javac -cp command or java -cp command.
ii) ant by using the properties attribute to include third party jars.

Now now need two clarifications

1)

You should not be misusing JDK's /lib folder to place 3rd party JAR's in. It makes your application less portable.



Now do you mean to say since the client's JVM & more specifically jdk\lib won't be having those third party jars , it makes our application less portable or is there any specific reasons.

2)

To save effort in typing you can easily wrap in a batch or shell file, depending on the OS used.


A batch file is similar to a text file only difference being saved in the extension .bat.
Here you are saying to wrap up the command javac & java in batch file.
Okay but using this we can run only one class right .

3)

You would also get more trouble like as you're struggling with now when you're using multiple JDK's


Can we use multiple JDK's in our application if yes normally in what situations they would opt for one

Regards.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any replies?
 
Rob Spoor
Sheriff
Posts: 22811
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Patience Is A Virtue.
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any replies?
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Remember that yours may not be the only Java application your client is running. Placing 3rd party jars in the standard locations may break other applications

2. Thats the idea, one batch or shell file per application.

3. I distinguish between an application compiled so that it can run under several different Java editions and "using multiple JDKs" at the same time. What are you talking about?

Bill
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

3. I distinguish between an application compiled so that it can run under several different Java editions and "using multiple JDKs" at the same time. What are you talking about?



I'm talking about the purpose of using multiple jdk's at the same time.
Regards.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a recipe for disaster to me even if you could do it.
 
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic