Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone there who can help me please.
 
Paul Clapham
Sheriff
Pie
Posts: 20764
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTML doesn't know the first thing about jar files, so that approach is not going to work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic