I think u need to use ServletContext.getResourceAsStream("pathOfFile")
or use Classloader.getResourceAsStream() when u deal with a resource
inside a war file or a jar file. Just do google search and you will get
an idea.

 

Regards,

Ramdas Sawant

________________________________

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Arif
Abbasi
Sent: Tuesday, January 23, 2007 9:23 PM
To: 'Post all your questions about iText here'
Subject: Re: [iText-questions] image not being loaded - possibly
classpathissue

 

Hi

 

I have a requirement to add a few images to my report title page. The
problem is that report generation classes are in Jar file and NOT part
of war file (where the action classes reside).  I cannot change this
packaging as this will have an impact. So, my class structure is like:

 

com.abc.fini.domain.report and underneath my report package reside my
reporter class say "PdfHtmlReporter.java".

 

I have tried putting images in a directory: webapp/fini/shared/images as
well just in /images directory within Jar file. Also tried adding images
in just root directory of my jar file.

 

So when I use this in line in my "PdfHtmlReporter.java" class to access
the images as below:

 

        Image verizGif=
Image.getInstance("webapp/fini/shared/images/vblogowhite.gif");

        verizGif.scalePercent(60);

        document.add(verizGif);

 

OR as

       Image verizGif= Image.getInstance("./images/vblogowhite.gif");

        verizGif.scalePercent(60);

        document.add(verizGif);

 

OR

 

        Image verizGif= Image.getInstance("vblogowhite.gif");

        verizGif.scalePercent(60);

        document.add(verizGif);

 

OR

 

        Image verizGif= Image.getInstance("images/vblogowhite.gif");

        verizGif.scalePercent(60);

        document.add(verizGif);

 

 

 

and other combinations, I am getting IOException saying document has no
pages. When I added this line to see how the path is being resolved:

 

        aFile = new File ("webapp/fini/shared/images/vblogowhite.gif ");

        if (aFile.exists()) {

            System.out.println("correct path " + aFile.getPath() + "
..->" + aFile.getAbsolutePath());

        } else {

            System.err.println("wrong path " + aFile.getPath() + " ..->"
+ aFile.getAbsolutePath());

        }

 

This resolves the path to c:/ webapp/fini/shared/images/vblogowhite.gif
on my drive. It looks like it does not know the image is within the same
Jar file where my Java classes reside. Instead it tires to go to find it
in the file system and fails.

 

OR

 

        aFile = new File("./images/vblogowhite.gif");

        if (aFile.exists()) {

            System.out.println("correct path " + aFile.getPath() + "
..->" + aFile.getAbsolutePath());

        } else {

            System.err.println("wrong path " + aFile.getPath() + " ..->"
+ aFile.getAbsolutePath());

        }

 

This resolves the path to
c:/java/jboss-4.02/bin/./images/vblogowhite.gif - which is again wrong. 

 

The above works if I run standalone Java program within eclipse. But
when I jar all my report generation classes and war all my action
classes and run in Jboss. All the Java classes work, the action classes
(in war) can call the report generation classes (in jar), however the
report generation classes (in jar) cannot access the image gif files
residing within the same Jar file. I cannot set explicitly the Jboss
classpath just for this image files, so that's not an option.

 

Can some one help me with this?

 

Thanks

arif
--------------------------------------------------------

NOTICE: If received in error, please destroy and notify sender. Sender does not 
intend to waive confidentiality or privilege. Use of this email is prohibited 
when received in error.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to