CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Posts
    20

    JAR doesn't work in an other directory

    Hi,
    I create executable JAR files in Eclipse and manually. The JAR contains the CLASS files and images that I use in my program. It works fine but when I move the JAR in an other directory the images don't get visualized. I opened the JAR to make sure that the image files are in and they are there. What's the problem?

  2. #2
    Join Date
    Jan 2006
    Location
    Baltimore, Maryland, USA
    Posts
    104

    Re: JAR doesn't work in an other directory

    ... what is the structure of your images? Do you have them separated in their own package?

    I have my problem where images are not showing up at all. How are you showing them, in code?
    Last edited by capitolc; November 23rd, 2009 at 09:44 AM.
    -= the best is yet to come =-

  3. #3
    Join Date
    Nov 2009
    Posts
    20

    Re: JAR doesn't work in an other directory

    I just have the images alongside the source/class files and show them by means of the default toolkit getImage() method.

  4. #4
    Join Date
    Jan 2006
    Location
    Baltimore, Maryland, USA
    Posts
    104

    Re: JAR doesn't work in an other directory

    I just moved my jar in different directories and I'm seeing the same thing. Once more, the image only shows when I run it from within Eclipse. Is this the same for you?

    Well, someone suggested I use the getResource to obtain the url path of the image. When I did that, I'm getting my image where ever I put the jar file.

    Code:
    URL urlIMG = getClass().getResource("/dir/filename.jpg");
    If you use this in place of .getImage(), your image may show up regardless of location of the jar file. Be sure to import the package "java.net.URL"
    -= the best is yet to come =-

  5. #5
    Join Date
    Jan 2006
    Location
    Baltimore, Maryland, USA
    Posts
    104

    Re: JAR doesn't work in an other directory

    Can I ask what options are you selecting when you create your jar file?

    I just want to make sure I am doing it the correct way. I am select the export option under file. From there, I am selecting 'runnable jar'. The launch config is the src/project I'm looking to export. But which are you selecting for your 'library handling'? I'm selecting 'package required libraries' - this only makes sense to me since I don't want to extract or leave out anything. right? what's your method?
    -= the best is yet to come =-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured