This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Java in General and the fly likes Exception in displaying data in a pdf format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Exception in displaying data in a pdf format" Watch "Exception in displaying data in a pdf format" New topic
Author

Exception in displaying data in a pdf format

ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
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.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Dear Hill,


So my java.exe is working fine.
Regards.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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

Joined: Oct 06, 2008
Posts: 338
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

Joined: Oct 06, 2008
Posts: 338
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?
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
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 ]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
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

Joined: Oct 06, 2008
Posts: 338
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

Joined: Oct 06, 2008
Posts: 338
Any replies?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

Patience Is A Virtue.
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Any replies?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
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

Joined: Oct 06, 2008
Posts: 338
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
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Sounds like a recipe for disaster to me even if you could do it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in displaying data in a pdf format