File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes My Program is not loading the image files in the jar. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "My Program is not loading the image files in the jar." Watch "My Program is not loading the image files in the jar." New topic
Author

My Program is not loading the image files in the jar.

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Hi all, I am Chaitanya, I developed a swing application and created a jar file to launch the application. The jar consists image files and class files. When i try to run the jar file the images aren't loading in the application. When I try to run the same jar with the images paced in the same directory of the jar, then my application is loading the images.

What is the problem here? I don't want to place the images separately. I want them in the jar only.

Can anyone tell me how to do this? Thank you all in advance.


Love all, trust a few, do wrong to none.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42944
    
  68
How are you trying to load the files? You can't use the File and FileInputStream classes (since the images are not files). But the jar file is in the classpath, so you can use something like getClass().getResourceAsStream(...).
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Hi Mr. Dittmer, I am using JTextPane to show the images. There is a html file in which I wrote all support information of my application. Using setPage(url) method of JTextPane class I am displaying the html file.

I choose this method because it saved my time in formatting the text and representing.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Anyone there who can help me please.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Not really. Ulf Dittmer asked you a question:
Ulf Dittmer wrote:How are you trying to load the files?

You completely ignored the question and told us something else:
chaitanya karthikk wrote:I am using JTextPane to show the images.

So if you aren't going to answer questions which were meant to find out more about your problem, it looks like you will have to make do with the other suggestions which Ulf made.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 806

Paul Clapham wrote:Not really. Ulf Dittmer asked you a question:
Ulf Dittmer wrote:How are you trying to load the files?

You completely ignored the question and told us something else:
chaitanya karthikk wrote:I am using JTextPane to show the images.

So if you aren't going to answer questions which were meant to find out more about your problem, it looks like you will have to make do with the other suggestions which Ulf made.


Hi Mr. Paul, thats what I said,. Mr. Dittmer said to use getClass().getResourceAsStream().
I wrote a HTML code which uses the image files. I wrote a java program which loads the HTML file. My program is loading the HTML file, the html file is not loading the images.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42944
    
  68
HTML doesn't know the first thing about jar files, so that approach is not going to work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: My Program is not loading the image files in the jar.