• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problems in executing a jar file

 
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I have some problem in executing the jar file... I have following scenario:
1. In normal scenario (if i don't have a jar file)...say I am creating a directory project..this will be my parent dir and i'll have test (this will have all class files) and images (this will have all images) as subdirectory of project. To run my program i have to go to my project dir at command prompt and can run by
c:\project>java test.app
(where app is my main class). and it runs very well.
2. Now I tried creating a executable jar with following cmmand
c:\project>jar cvf temp.jar test/*.* images/*.* entrypoint.mf
while entrypoint.mf has following line with an extra carriage return at the end:
Main-Class: test/app
when I issue following command at the prompt:
c:\project>java -jar temp.jar
my programs runs prefectly fine.Take care it also has test and images folder also with all relative files extracted as this was original folder from where I have created the jar file. But if i copy this jar file into another folder say newProject and try to run program like this:
c:\newProgram>java -jar temp.jar
it runs my program but without the images...why?

1. Is jar file itself not contains all information for every files it has included?
2. Do I have to include images directory and others (except class files) separately?
3. What is a solutions for it? where am I wrong?

Please help me sort the issue..
regards,
Arun
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to use ClassLoader.getSystemResource/getSystemResourceAsStream to load your resource files.
 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ilja for your reply...but I failed to use it..I tried using the ClassLoader.getSystemResource method but it is giving me error..perhaps I am doing something weird...can you help me in modifying the following code for me..this lies in my class called myapp.java which is under package test.
I am using images in following three fashion..

1. Image img = Toolkit.getDefaultToolkit().getImage("images/picon.gif");
2. JLabel background = new JLabel(new ImageIcon("images/mbg.jpg"));
3.ImageIcon i1=new ImageIcon("images/buttons/go/go.gif");
regards,
Arun :roll:
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
arun,
What do your attempts at using the suggested method(s) look like?
 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Dirk for your intrest in this post..I earlier thought of giving code also..but was a bit reluctant as perhaps I was not able to understand the method very well and thought that perhaps asking is better answer(as a matter of fact i was afraid if some one will crib or laugh at me..anyway let me find some courage)..but you're right I *must* put whatever I tried.. here is what I tried...

1. URL url = abc.class.getResource("images/picon.gif");
Image img=Toolkit.getDefaultToolkit().getImage(url);

abc is the class where I am tying to load the image..
It failed to find the image..
2. I than tried with

URL url = new LoadClass().getResource("images/picon.gif");
Image img=Toolkit.getDefaultToolkit().getImage(url);

The Loadclass is like this:

package test;
public class LoadClass extends ClassLoader
{
public LoadClass()
{
super();
}
public LoadClass(ClassLoader c)
{
super(c);
}
}

It worked but failed in second case:

JLabel background = new JLabel(new ImageIcon("images/mbg.jpg"));

3. Tha lastly I tried with this:

Enumeration en=(Enumeration)ClassLoader.getSystemResource("images/picon.gif");
Image img = null;
while(en.hasMoreElements())
{
img=(Image)en.nextElement();
}

but it never compiled..
Can you help me...
regards,
Arun
[ June 10, 2002: Message edited by: arun mahajan ]
[ June 10, 2002: Message edited by: arun mahajan ]
 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can somebody pl help me in this.

thanks
Arun
 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope someone will find time from this promotion craze and help this poor guy for this post
Arun
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This conversation is being continued here...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic