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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply 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: 779

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: 35237
    
    7
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(...).


Android appsImageJ pluginsJava web charts
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 779

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: 779

Anyone there who can help me please.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

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: 779

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: 35237
    
    7
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: My Program is not loading the image files in the jar.
 
Similar Threads
Class Loader
JMF can't play media file in a jar file
Add Image on to JFrame in jar file
Image loading very slow from URL
Problems loading images from application JAR