Reading Images from JAR Files

Hi,
I am having a very difficult time being able to read images from a JAR file via my Applet. I have tried everything that I know about with no luck. The only way I can get this to work is to store the images individually in a sub directory of public_html on the websever. This works, but I would like the images to come down in a JAR file for performance reasons.
I am using Internet Explorer 5.5 for my browser. I checked the options and everything seems to be in order, but......
I would appreciate any feedback that anyone might have on this topic..........
Thank You....

once in a jar file i inserted a image
the jar file on clicking starts an frame.
so the image was for getting that image at the icon place at top and at minimized window
i could not get that image from jar file by new imageicon().getimage();
but i get the image if it is in the directory in which jar file is.....
can one explain the reason

Similar Messages

  • Problem loading image from jar file referenced by jar file

    First, I searched this one and no, I didn't find an answer. Loading images from jar files has been pretty much done to death but my problem is different. Please read on.
    I have my application, a straight up executable running from Eclipse. It uses a jar file, call it JarA. JarA launches a GUI that is located in another jar file. Call it JarB. To recap:
    My application calls JarA -> JarA loads classes from JarB -> JarB looks for images to place in a GUI it wants to show on the screen
    When JarB goes to load an image the following happens:
    java.lang.NullPointerException
         at sun.misc.URLClassPath$3.run(URLClassPath.java:316)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.misc.URLClassPath.getLoader(URLClassPath.java:313)
         at sun.misc.URLClassPath.getLoader(URLClassPath.java:290)
         at sun.misc.URLClassPath.findResource(URLClassPath.java:141)
         at java.net.URLClassLoader$2.run(URLClassLoader.java:362)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findResource(URLClassLoader.java:359)
         at java.lang.ClassLoader.getResource(ClassLoader.java:977)
         at org.cubrc.gmshell.gui.MainWin.preInit(MainWin.java:152)
         at org.cubrc.gmshell.gui.MainWin.<init>(MainWin.java:135)
    The code from JarB that loads the image looks like this:
              URL[] oSearch = {Main.class.getResource("images/")};
              URLClassLoader oLoader = new URLClassLoader(oSearch);
              imgIcon = new ImageIcon(oLoader.getResource("icon.gif"));
              imgMatchRunning = new ImageIcon(oLoader.getResource("gears.gif"));
              imgMatchStill = new ImageIcon(oLoader.getResource("gears-still.gif"));
              imgMagnify = new ImageIcon(oLoader.getResource("magnify.gif"));This looks right to me and JarB certainly has an images directory with those files. But I'm in hell right now because I don't know where to place the images to make this work or if you can even attempt to load images with a dependency chain like this.
    Any help very appreciated!

    Have you tried to move your image-files out of the jar file and place them in the sam folder as the jar-file? I think that would help.
    When you try to load the image-file you get the NullPointerException because the program tries to read a file it can't find. Remember that a jar file IS a file and not a directory.
    If you want to read somthing inside the jar-file you need to encode it first.
    Have you tried to read the jar-file with winRar. It makes it easy to add and remove files in your jar-file.

  • Read filenames from jar-file

    Hi,
    I want to read image names in a jar-file directory in a web start application. This used to work in previous versions of jdk,
    but when I use jdk 1.6.0_20 I get this errormessage:
    "http:\server:8080\test\client.jar The filename, directory name, or volume label syntax is incorrect".
    Why doesn´t this work anymore?
    Some of my code looks like this:
         getFiles("images/toolbuttons/val/", ".gif", true);
         public String[] getFiles(String catalog, String fileNameEnd,
             boolean removePath)
              JarFileFinder jarFileFinder = new JarFileFinder();
              String jarFilePath = jarFileFinder.getClassLocation(
                  this.getClass().getName());
              String[] files = null;
              try
                   if (fileNameEnd != null)
                        fileNameEndFilter = new FileNameEndFilter(fileNameEnd);
                   files = getFilesInJar(jarFilePath, fileNameEndFilter, catalog,
                       removePath);
              catch (Exception e)
                   MessageUtil.messageOk(null, this.getClass().getName(), e.getMessage());
              return files;
         private String[] getFilesInJar(String jarFilePath, FilenameFilter filter,
             String catalog, boolean removePath)
             throws Exception
              ZipFile zipFile = new ZipFile(jarFilePath);
              Enumeration e = zipFile.entries();
              String name;
              ZipEntry zipEntry;
              ArrayList filesList = new ArrayList();
              while (e.hasMoreElements())
                   zipEntry = (ZipEntry) e.nextElement();
                   name = zipEntry.getName();
                   if ((filter == null || !filter.accept(null, name)) ||
                       (catalog != null && !name.startsWith(catalog)))
                        continue;
                   if (removePath == true)
                        name = name.substring(name.lastIndexOf("/") + 1);
                   filesList.add(name);
              String[] files = new String[filesList.size()];
              for (int i = 0; i < filesList.size(); i++)
                   String s = (String) filesList.get(i);
                   files[i] = s;
              return files;
    public class JarFileFinder
         public String getClassLocation(String classname)
              try
                   Class clazz = Class.forName(classname);
                   if (clazz == null) return null;
                   URL url =
                       clazz.getProtectionDomain().getCodeSource().getLocation();
                   String location = url.toString();
                   if (location.startsWith("jar"))
                        url = ((JarURLConnection)
                            url.openConnection()).getJarFileURL();
                        location = url.toString();
                   if (location.startsWith("file"))
                        return new File(URLDecoder.decode(url.getFile(), "UTF-8")).getAbsolutePath();
                   else
                        return URLDecoder.decode(url.toString(), "UTF-8");
              catch (Exception e)
                   MessageUtil.messageOk(null, this.getClass().getName(), e.getMessage());
              return null;
    }

    AndrewThompson64 wrote:
    Lisa_R wrote:
    ..I tried to remove the URLDecoder, but the result was the same. I still get:
    "http:\server:8080\test\client.jar The filename, directory name, or volume label syntax is incorrect".Given an URL should use '/' as opposed to '\', and starts with 2 '/' rather than one, it is not surprising that URL was rejected. Strange as it may seem, programming by typing random characters into an editor will rarely, if ever, work to create a working application.Yes, I agre that it´s not that surprising that the URL was rejected (even though the URL work in firefox and IE). But I didn´t write it that way. The code that put the URL together worked fine in previous versions of the jdk.
    >
    ..The reason why I want to read the filenames from the jar instead of including a list of the names is that if you
    want to add an image then all you have to do is include it in the directory.. That is largely irrelevant, since the Jar needs to be freshly built, uploaded by the developer, and downloaded by the client. Since all of that needs to be done for the addition of a single image, you might as well add an Ant task to the build that provides a single file (like I suggested earlier) that lists the resources of interest. It would take less time to write an Ant task, than debug all the hoops the code is currently jumping through(1) in order to get the information of interest.
    If this was the only place were this method was used I would agre with you, but unfortunatelly it´s not. The application dosen´t only read image filenames it also reads class-names.
    1) And even if you got that working, it would be likely that Sun would introduce some change in the next version of Java that breaks it again. My advice is to stop fighting it, and go with the flow.Thats not good of course! But it has been working for a long time, so I think I will try to make it work again....
    Is there someone out there who has done this or knows how to do it I would appreciate some help! :-)

  • PJC - Loading Images from JAR Files

    I'm developing a PJC class that involves loading images. I would like to be able to find and use an image contained in a JAR file just like the built-in Forms items do; not the JAR file where my class is contained but any external ones defined in the server archive settings.
    I have seen the loadImage method in the demo RolloverButton class but this only loads images from the class's JAR and not any others.
    Is there a VButton method or an Oracle loader class for finding image resources from the defined JAR archives? If not, could someone supply some code for achieving this.
    Thank you.

    Hi,
    the jar file name the images are in shouldn't matter for the code as long as the package name is preserved. If you want to see it with your own eyes, do the following
    1. Back up demo90.jar
    2. Create a copy of it and call it demo90img.jar
    3. Open demo90.jar in winzip and remove all images
    4. Open demo90img.jar and remove all Java classes
    5. add ,/forms90demo/jars/demo90img.jar to the archive_jini tag of a demo you want to test this on
    6. Run the application and see the images despite the fact they are now in a separate jar file. Note in the Jinitiator console that the new jar files are downloaded and replace the existing, cached, jars
    7. Run an application that doesn't have demo90img.jar configured to see that the images are missing.
    Frank

  • Loading images from jar file

    i use the instruction below to load image contained in my jar file for distribution application but the image doesn't appear
    icon = new ImageIcon("images/logo_tunisiana.GIF");
    the jar file contain the image under a subdirectory called images.
    Witch code sample have i to use ?
    thanks in advance

    I have an applet that is packaged in a jar file with images. I can access the images using:
    aIcon = new ImageIcon(KeyboardApplet.class.getResource("images/keyimages/a.jpg"));

  • How can I use images from Jar files

    Hi,
    I would like to use the images provided by ADF if any on my UI like pencil Icon for Edit, pushpin for freeze and so on.
    How can I refer them in Image source. Custom images I have stored in my pubilc_html directory and using them.
    Do I need to unzip that to my project public_html directory ?
    Thanks,
    Satya

    Hi Satya,
    you can reference those images via the ADF resources servlet once you know the correct URL to an image.
    For example, in 10g the pencil icon is called lovi.gif, so its full URL will be
    http://host:port/context-root/adf/images/oracle/lovi.gifand you can use it in an af:objectImage like
    <af:objectImage source="/adf/images/oracle/lovi.gif" />Hope this helps,
    Patrik

  • Write/read image to avi file, VI works incorrectl​y from the second run

    Hi everybody, in my labview I write image from IMAQ USB to avi file and read image from avi file, the VI runs correctly at the first run then after that it goes wrong, I can write/read only one frame and it terminates automatically. Does anybody know why and how to solve this?
    Thanks a lot,
    Hannah

    Without seeing your code I can't comment specifically, but if it runs correctly the first time and then stops be looking for something that is not getting reinitialized correctly. Also what exactly do you have to do to get it to work again? Close and reopen the VI? Restart LV? Restart the computer?
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Applet : How to use Images in Jar file

    I want to put all images into a jar file to improve speed of loading.
    But how to invoke images from Jar file?
    Thanks.

    @Op. It's very important for a developer to know how to find information, and that skill usually comes with experience. Google is one of the best ways to find information and solutions to the most common problems.
    Kaj

  • Read images from external jar file (Sun's Java L&F Graphics repository)

    Hi!
    I don't know how to read images from an external jar file. Sun has a Java Look and Feel graphics repository that contains a lot of good images that can be used on buttons and so on. This repository is delivered as a jar file, containing only images, and I want to read the image files from that jar file directly without including them inside my application jar file. The application and image jar files will be in the same directory.
    I have absolutely no clue how to solve this. Is it necessary to include the images inside my application jar file or is it possible to have them separate as I want.
    Would really appreciate some help!
    Best regards
    Lars

    Hi,
    There is two ways :
    1) Add your jarfile to the classpath.
    Use the class loader :
    URL url = ClassLoader.getSystemResource("your/package/image.gif");
    Image im = (new ImageIcon(url)).getImage();
    or
    Image im = Toolkit.getDefaultToolkit().getImage(url);2)If you don't want to add the jar to the classpath you can use this (under jdk 1.4):
    import java.util.*;
    import java.util.jar.*;
    import java.awt.*;
    import java.io.*;
    import java.awt.image.*;
    import javax.imageio.*;
    public class ImageUtilities {
         public static Image getImage(String jarFileName, String fileName) {
              BufferedImage image = null;
              try {
                   JarFile jar = new JarFile(new File(jarFileName), false, JarFile.OPEN_READ);
                   JarEntry entry = jar.getJarEntry(fileName);
                   BufferedInputStream stream = new BufferedInputStream(jar.getInputStream(entry));
                   image = ImageIO.read(stream) ;
              catch (Exception ex) {
                   System.out.println(ex);
              return(image);
    }I hope this helps,
    Denis

  • Unable to read TLD "META-INF/jsf_core.tld" from JAR file "file:

    Hallo everybody :-)<br /><br />i've installed Workflow-Server + ARES + FormManager. When i call localhost:8080/adminui i can log in and the browser loads the next site --> it fails and says:<br /><br />org.apache.jasper.JasperException: Unable to read TLD "META-INF/jsf_core.tld" from JAR file "file:/C:/Adobe/LiveCycle/jboss/server/all/tmp/deploy/tmp56414LiveCycle.ear-contents/admi nui.war/WEB-INF/lib/jsf-impl.jar": org.apache.jasper.JasperException: Failed to load or instantiate TagExtraInfo class: com.sun.faces.taglib.FacesTagExtraInfo<br />     org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:5 0)<br />     org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)<br />     org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:183)<br />     org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:181)< br />     org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:418)<br />     org.apache.jasper.compiler.Parser.parseDirective(Parser.java:483)<br />     org.apache.jasper.compiler.Parser.parseElements(Parser.java:1539)<br />     org.apache.jasper.compiler.Parser.parse(Parser.java:126)<br />     org.apache.jasper.compiler.ParserController.doParse(ParserController.java:220)<br />     org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)<br />     org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)<br />     org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)<br />     org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)<br />     org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)<br />     org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)<br />     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)<br />     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)<br />     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)<br />     javax.servlet.http.HttpServlet.service(HttpServlet.java:810)<br />     com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)<b r />     com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)<br />     com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)<b r />     com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)<br />     com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)<br />     javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)<br />     com.adobe.framework.SecurityFilter.doFilter(SecurityFilter.java:177)<br />     com.adobe.idp.um.auth.filter.PortalSSOFilter.doFilter(PortalSSOFilter.java:106)<br />     com.adobe.framework.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter .java:161)<br /><br />Any idea what' wrong?<br /><br />Thanks,<br />Valerio

    Hi Howard,
    thank you for your post.
    I actually new about the problems with the jvm version. Still i wanted to ask, cause there are different reports on this `java problems` and even though the 1.4.2_08 seems to be the best version (by the way this version is not to be downloaded any longer *sig*), there are people getting all installed with other versions. I couldn't find any regularity in the misbehavior of the servers while installing.
    I finally achieved and got everything working ... but very slow. Loading the adminui or BAM features takes very long time (over one minute). Have you already had this delay. Any hint?
    Thanks again,
    Valerio

  • How to read an image from an file using jsp

    reading an image from an file present on local disk using jsp

    Server-local or client-local? First, File I/O, second: better get a new job.

  • Problem loading Applets from Jar files on 64 bit machine

    I am developing an applet (extends Applet but uses swing components) using JDK 1.6 (Though these problems still happen in JDK 1.7) and I am unable to get the applet to load on a 64 bit machine in most cases. The web server(s) are running on localhost and I am connecting on the same machine using a local network ip address (such as 192.168.*.*)
    Below are all of my test results. Can someone provide a suggestion for repairing this? The Windows Server machine is a clients computer I access to it via remote desktop but I can't do much with it though I do have administrator rights. The Windows 7 machine is my development platform so I have been able to do extensive testing on it.
    This problem is presenting in the following environments when trying to load an applet from JAR files in a HTML document using the Applet or Object tag.
    Windows Server 2008 (Intel Chipset)
    Tested Browsers:
    Internet Explorer 9 (32 bit) - Shows it is blocked by default then simply shows an x when loaded from a web page, same result when loading from local drive.
    Windows 7 Home Premium (AMD Chipset)
    Tested Browsers:
    Firefox 6.0.1 (32 bit) - Java logo shows with spinner, after a few minutes there is finally an error that a class in the jar was not found
    Internet Explorer 9 (32 bit) - Java logo shows with spinner, after a few minutes there is finally an error that a class in the jar was not found
    Internet Explorer 9 (64 bit) - Java logo shows with spinner and most of the windows desktop manager freezes, keyboard is the only thing that responds so you can alt-tab to another app to regain control of the desktop.
    Chrome (32 bit) - Java logo shows with spinner, after a few minutes there is finally an error that a class in the jar was not found
    The only way I have been able to get a Java applet to run on a 64 bit machine are the following ways.
    Firefox 9 nightly (64 bit) works perfectly! Go Firefox!
    Internet Explorer 9 (32 bit) loading directly from drive (c:\...)
    Chrome (32 bit) loading directly from drive (c:\...)
    Firefox 6.0.1 (32 bit) loading directly from drive (c:\....)
    Can someone please help! I've been fighting with this bug for over a week and I can't find anything that will solve it, I have noticed that in some cases if my jar has very little code in it than it will run on the server, but the minute I start adding things to it the jar won't load anymore.

    jschell wrote:
    rritoch wrote:
    I am developing an applet (extends Applet but uses swing components) using JDK 1.6 (Though these problems still happen in JDK 1.7) and I am unable to get the applet to load on a 64 bit machine in most cases.
    To clarify...
    1. You have tried it on 32 bit machine? Exactly which OS?I tested this on Windows Vista Business which is in 32 bit mode and the applets run without any problems
    >
    2. Your only 64 bit tests have involved 2008/Win7?
    If so then I would suspect something with windows not java. Probably permissions.
    The web server(s) are running on localhost and I am connecting on the same machine using a local network ip address (such as 192.168.*.*)
    Yes, I haven't tried running the jars on other operating systems.
    >
    I don't understand that. If you are running on localhost then you should connect to localhost. If running on an IP then you should connect to that. Perhaps you meant that you have tested using both of those?I'm testing using the lan ip address but I'm connecting from the same machine. I've tried localhost and that didn't work so I tried lan ip since that will likely have a different java security context than localhost. At first I was blaming the IIS server but I downloaded the jar directly and using HTTP fox was able to verify that the jar is being sent with the correct mime-type and that the server can upload the jar file without a problem. This leaves me to believe the problem is with Java.

  • How to extract html file and folder from jar file

    Hi all ,
    I should to submit my project tomorrow . plz help me .
    In my project jar file I have html page that should run when I use the program, I can't extract it . Also it have folder that contain some files that My program should use it . I dont know how to use it from jar file or how to extract it . plz help me.
    If you could I need java could for that.
    Thanks alot.

    Hi all ,
    I should to submit my project tomorrow . plz help me .
    In my project jar file I have html page that should run when I use the program, I can't extract it . Also it have folder that contain some files that My program should use it . I dont know how to use it from jar file or how to extract it . plz help me.
    If you could I need java could for that.
    Thanks alot.

  • Add images in jar file

    how to add images in jar file?

    Check this article in ADF code corner:
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/86-images-from-jar-427953.pdf
    Thanks,
    Navaneeth

  • How to use image from a file in signature appearance.

    Hi,
    I am creating a Plugin for acrobat 9, using PubSec using DocSign sample as basis. I have created the appearance using text objects and the logos data that came with the DocSign sample. But I want to use image from a file (like, jpg) in the signature appearance creation. So far the documentation doesnt tell how to achieve this.
    Can you please tell me in a  "How-to" kinda way to achieve this?
    Thanks in advance.

    Thanks for ur prompt reply.
    There are so many samples in the sdk. which one is the "sample for adding images."?

Maybe you are looking for

  • Dvi to s- video (audio issue

    I have a macbook pro and purchased a DVI to S-video cable to watch a slideshow through iphoto. I am able to see the slideshow; however, I cannot hear any audio through the TV? How do I correct this issue? joe

  • BPELConsole in 11g?

    Hi Forum, In the version prior to 11g of SOA there was a component called BPELConsole, what is the equivalent of it in 11g? How can I test my service after deployment? Thanks in advance!

  • Problem with setMaximumSize [JToggleButton]

    Hi to all. I have a little problem when I set Size of JToggleButton. I have a panel that is in a JSplitPane. This panel has GridLayout because I put into many JToggleButtons. I set PreferredSize, MinimumSize and MaximumSize. When application starts P

  • HOW CAN I ADD FOREIGN RADIOS TO ITUNES?

    HOW CAN I ADD FOREIGN RADIO STATIONS TO ITUNES? I HAVE NO URL'S.  I HAVE THESE STATIONS IN MY BOOKMARKS BUT WANT TO CONCENTRATE THEM ALL IN ITUNES. THE GENIUSES HAVE NO ANSWER NOR DOES APPLE VIA TELEPHONE.

  • Exit Code: 34 for windows7

    -------------------------------------- Summary -------------------------------------- - 1 fatal error(s), 0 error(s), 0 warning(s) FATAL: Payload '{3F023875-4A52-4605-9DB6-A88D4A813E8D} Camera Profiles Installer 6.0.70.0' information not found in Med