Problem with images in .jar file

Hi all!
I've got a severe problem when deploying an application via web start:
the images withhin a deployed .jar file are not found.
So far I've tried a number of things to get the images back, none of which are working.
I've found different threads concerning this topic, e.g.:
http://forum.java.sun.com/thread.jspa?threadID=396363
http://forum.java.sun.com/thread.jspa?threadID=465795&messageID=2141351
but sadly, they didn't help me out.
Here is my code I'm using:
  private ImageIcon loadIconFromClassLoader(String tszRelPath)
    ImageIcon tIcon = null;
    cCat.info("tszRelPath = "+ tszRelPath);
    // this line simply leads to a crash of the whole application
    //tszRelPath = tszRelPath.replaceAll("\\", "/");
    if(!tszRelPath.startsWith("/"))
      tszRelPath = "/" + tszRelPath;
    cCat.info("modified tszRelPath = " + tszRelPath);
    URL tURL = ClassLoader.getSystemResource(tszRelPath);
    if(tURL == null)
      // this too crashes my application
      //tURL = PlainResourceProvider.class.getResource(tszRelPath);
    if(tURL != null)
      tIcon = new ImageIcon(tURL);
    return tIcon;
  }I've also tried
PlainResourceProvider.class.getClassLoader().getResource()PlainResourceProvider is part of the .jar that involves the images.
Of course all the .class files in the .jar file are easily accesible
I would be so thankful, if just anyone could help me to solve this problem.
I am going crazy.
Thanks in advance, Christoph

You should take care of the directory structure according to the package structure.
I for example have this jar:
C:\source\java\ebank2_util\smsunlock>unzip -l pro-ebank_sms_unlock.jar
Archive:  pro-ebank_sms_unlock.jar
Length    Date    Time    Name
      0  10-28-05  17:27   hu/
      0  10-28-05  17:27   hu/khb/
      0  10-28-05  18:17   hu/khb/smsunlock/
    256  11-07-05  16:33   hu/khb/smsunlock/DButils$MySQLException.class
   4229  11-07-05  16:33   hu/khb/smsunlock/DButils.class
   1700  11-07-05  16:33   hu/khb/smsunlock/GUI$1.class
   2318  11-07-05  16:33   hu/khb/smsunlock/GUI$2.class
    988  11-07-05  16:33   hu/khb/smsunlock/GUI$3.class
   1402  11-07-05  16:33   hu/khb/smsunlock/GUI$mywl.class
   5630  11-07-05  16:33   hu/khb/smsunlock/GUI.class
    818  11-07-05  16:33   hu/khb/smsunlock/LimitedLength_TextField.class
   2452  11-07-05  16:33   hu/khb/smsunlock/Main.class
    900  11-07-05  16:33   hu/khb/smsunlock/MyInputStream.class
      0  11-07-05  16:33   META-INF/
     98  10-27-05  15:53   META-INF/manifest.mf
     90  11-07-05  16:33   hu/khb/smsunlock/properties
  20881                    16 filesAnd the resource is loaded like this from hu.khb.smsu.Main:
InputStream is = new MyInputStream( Main.class.getResourceAsStream( "properties" ) );

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.

  • Problems with jdbc and .jar files.

    I am having a problem with connecting to my database when running my .jar file as an executable.
    It connects correctly when I use the java command in command prompt and it also runs correctly when using my IDE.
    Is there something that needs to be added to the manifest or in the code it self inorder for the program to find the JDBC driver correctly?

    This is the error message that I get:
    java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at AboutFrame2$Connect.getConnection(AboutFrame2.java:109)
    at AboutFrame2$Connect.displayDbProperties(AboutFrame2.java:127)
    at AboutFrame2.<init>(AboutFrame2.java:72)
    at MainStartFile2.main(MainStartFile2.java:7)
    Error Trace in getConnection() : net.sourceforge.jtds.jdbc.Driver
    Error: No active Connection
    I think that it is because it cannot find the driver. I am going to add the path to the manifest and see if that works thank you for all the help.

  • Problems with ClassLoader and Jar-Files

    1. I'm not good in englisch (writing).
    2. I have the problem, that i want to load a object from an application in Jar-File A out of the Jar-File B. I set the CLASSPATH for B with System.setProperty("java.class.path", <ClassPath>); . Then i tried to get the Class-object from a class of B. I do it with getClass().getForName("package.Name");.
    But everytime i get a ClassNotFoundException. Where is the Error? Or how can i load a class out of a Jar-File and get an instance? I hope you can help me..
    Tobain

    The error is that classes are loaded from the classpath as it existed when the program started. Changing the system property that was copied from the classpath has no effect, as you have seen. I have heard that you can write your own ClassLoader if you want to load classes from arbitrary locations, but I do not know how to do that myself.

  • Problems with exporting a .jar file

    Hi there,
    I'm working on a small java game and wanted to export in as a jar file.
    The program runs fine in the IDE and it generates the jar without any warnings.
    However, when i try to execute the jar, it simple "blinks" the basic frame and exit.
    A better description might be, that it looks like the Jframe opens, but then closes again quickly.
    I'm using Eclipse as IDE, and follow the Export wizzard.
    My project is devided like this:
    package : framework.
    package: sound.
    package: sprite.
    folder: sounds.
    folder: sprites.
    I'm guessing it somehow can't find the images, but as i said, it runs fine in the IDE.
    My MANIFEST looks like this:
    Manifest-Version: 1.0
    Sealed: true
    Main-Class: framework.EagleFlight
    Hope you can help.

    Hi,
    Thanks for your answer.
    I can export it from Netbeans, but not Eclipse.
    However, from Netbeans I get no sound, when executing the jar.
    Anyway, I'm happy enough with the exporting, now I just need to get sound, for which i have
    made another thread here.

  • Problems with creation of JAR file

    Hi!
    I can't succeed in creating a JAR file for my application.
    I've followed the guide at http://java.sun.com/docs/books/tutorial/deployment/jar/basicsindex.html
    but apparently im doing something wrong....
    I've tried doing an extra Manifest file aswell as "Setting an Entry Point with the JAR Tool" as written in the guide. noen with success however :(
    I always get the error "Could not find the main class. Program will exit." from the JVM when I try to run my JAR file.
    Structure of my program:
    C:\searchpath\moresearchpath\projectname\src\
    inside src\ there are 3 packages called; "graphic", "client" and "server".
    I want to make a JAR file from the files in the "server" package. The "server" package consists of these following 4 files(and nothing more); "ClientHandler.java", "TestServer.java", "ServerModel.java", "ServerController.java".
    "TestServer.java" is my main class!
    This is an example of a command I've done in order to try to make a JAR file:
    "C:\searchPathToWhereJavaIsInstalled\jdk1.6.0\bin\jar cvfe sgwserver.jar server.TestServer server\*"
    This doesn't generate any error. However when I try to start the .jar I get following message "Could not find the main class. Program will exit."
    I've also tried creating manifest file manually but without success (with UTF-8 encoding and not double .txt ending on file)
    This is how the "Manifest.txt" file has looked when I've tried making one:
    Main-Class: server.TestServer
    I have used Netbeans 5.5 and Java SE 6 for development
    What am I doing wrong? Please help me :(

    If I try to run the one generated from Netbeans I get the following error message: "Failed to load Main-Class manifest attribute from C:\searchpath\moresearchPath\projectName\dist\projectName.jar"
    The thing is I need 2 JAR files, one that contains the files in the "server" package and one that has all other files. The other one is an applet and the files in "server" package are a standalone application.
    How do I get the standalone application's JAR file to work?

  • Problem with addition of jar file to DC

    Hi WDers,
    I have a DC of type WD.
    I'm trying to add com.sap.security.api.jar file to this component so that I can get IUser and work on it.
    I have added this security jar file as an External jar file to the DC. But whenever I try to DC->Build, the jar entry is going away. So the Build is failing.
    Can you kindly let me know why this is happening?
    Or is there any other way to add a jar file so that I can use the IUser interface in my view?
    Thanks in Advance
    RK

    Hello,
    Add the Standard DC "com.sap.security.api.sda" from the SAP-JEE. This ahould solve the problem.
    To do that follow the steps:
    1. Go to the "DC Metadata" option available under the DC.
    2. Go to "Used DCs" and choose "Add used DCs" from the context menu which appears on a right click at the Used Dcs option.
    3.Select "com.sap.security.api.sda" under SAP-JEE and choose finish.
    4. Build the DC to gain access to the IUser and other related classes.
    Bala.

  • Problem with using external jar file

    Hi
    I was using mail.jar library for swing application to send and receive emails. It just works perfect when I run with netbeans. But when I run the executable jar file at dist folder it runs but mail related functions doesn't work.What should I do now to make it work with mail features outside netbeans.
    thanks
    vinay
    Edited by: 899657 on Dec 24, 2011 5:07 AM

    899657 wrote:
    No. Because I am running the jar file which is created by netbeansNetbeans creates a 'dist' directory in which it puts your jar and a "dist/lib' directory in which it puts the dependent jars that are added to the project using 'project right mouse click'->Properties->Libraries. I would expect to see this 'dist/lib' directory contain mail.jar and activation.jar and any other jars that your jar needs. Within your program jar's manifest I would expect to see the Class-Path attribute have relative reference these jars ( lib/mail.jar lib/activation.jar ) and for the Main-Class attribute define your main class.
    Given this setup then you should be able to just type -
    java -jar yourjar.jarto run your program.

  • Problem with installer of jar file....!!!

    Hi All,
    I had created a installer of my java application. after the installation when i click on jar file,jar file will execute but not locating to installed program files folder.
    But if i set the Startin property of shortcut (Start-->Programs-->Folder-->JarFile--> Right Click-->properties) then it run OK.
    Problem is that, i have to set that property manually..
    If you people having any solution of this, then please let me know.
    Thankx in advance...

    Hi
    see http://forum.java.sun.com/thread.jspa?forumID=256&threadID=501000
    Hope that help,
    Jack

  • Problems with Manifest building jar file

    Hello all,
    i try to deploy my application in a jar file. I also have some libs to deploy with my application. My app.jar and my lib.jar are in the same directory. My Manifest looks like:
    Manifest-Version: 1.0
    Main-Class: parser.Parser
    Class-Path: lib.jar
    Class-Path: ...Still get the error: NoClassDefFoundError.
    Main Class is found but not my lib. Can somebody help?
    regards ak

    Hi CeciNEstPasUnProgrammeur,
    many thanks. I was blind reading the Java tutorial...
    Best regards,
    ak

  • I have a problem with runing a jar file

    after i compiled the hole project into a jar file when i want to run it i get this error:
    ========================================================
    C:\Documents and Settings\BlackShark>java -jar D:/eclipse/workspace/Bazooka/E
    xe/Bazooka-Server.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: ro/blackshark/Bazo
    oka/Server/TestServer

    Looks like you're missing that class in the jar file. Open your jar file and check if the class is there and the path is correct.

  • InDesign Transparency Effects - Problems with Image Quality and File Size

    Hello,
    We are experiencing new problems exporting InDesign files to PDF.
    To summarize, though our largest workflow is to create files for offset printing, we also deliver our work to PDF for mounting on a website so our clients can download directly from the web. Our new problem is Transparency Effects, and creating a PDF that will both have a high quality (or resolution), and be a small file size.
    We are working with multiple page documents (24 to 48 pages), and would very much like to work with InDesign Transparency Effects. However, after spending much time testing a variety of PDF types, we are finding there is a radical difference between quality and file size. I was curious if anyone has had these problems, and if there is a simple answer. InDesign is an incredible program that allows us to design on the fly with Transparency Effects, but, if we are going to experience these problems, we will have to eliminate these wonderful tools.
    Can you help me or lead me to information online that will help.
    Thank you,
    Lain

    Please don't post in multiple forums. Your question has nothing to do with the PDF language and specifications, but rather PDF workflow or InDesign. I've responded to your other posting and am closing this thread.
    - Dov

  • Problem with Image IO jar on Oracle Form

    I'm using a PJC as a TextEditor on Oracle Form. The PJC uses JAI ImageIO jar that holds javax.imageio package. When I use the PJC right from Oracle Form it doesn't work whereas it works well independently. Please have a look on JInitiator Console message given below and let me know if possible how to get around this:
    Drag Enter
    Source: java.awt.dnd.DropTarget@1abd68
    Drag Exit
    Possible flavor: application/x-java-file-list; class=java.util.List
    Exception occurred during event dispatching:
    java.lang.NoClassDefFoundError: javax/imageio/ImageIO
    at HTMLEditor.drop(HTMLEditor.java:591)
    at java.awt.dnd.DropTarget.drop(Unknown Source)
    at sun.awt.dnd.SunDropTargetContextPeer.processDropMessage(Unknown Source)
    at sun.awt.dnd.SunDropTargetContextPeer.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    I need to tell that if I unjar my jar used for pjc I find that ok for javax.imageio package and also if I run my program other than on Oracle Form, it runs fine. I know regarding the signing issue of jar required to run pjc , so don't get concerned of it.
    Thanks
    Rashed

    Hi...thanks for your suggestion. Which JavaPlugin do you suggest to implement? If you mean to upgrade the jre that is an installer found for various jdk versions, I have that...in that case I only need to know which version should I use. Moreover, installing that tool the jre of jdk gets upgraded...I don't know how to upgrade Jinitiator...please let me know this issue.
    Rashed

  • Strange problem with my build JAR

    Hiii everybody... I'm having a strange problem with my build (JAR file)... when I work with the Eclipse and I click in the table that returns the clients stored in my PostGre database it works fine, but when I build my application and it generates my JAR file and I open it and click in the same table to return the objects that I have.. it does not appears anymore.. just show when I work with eclipse... and the database is the same for both.
    I already checked the database path in my properties file... and the application recognize the database because I can login and there isn't any runtime exception...
    In that application I work with Hibernate and Spring... for me it is very strange because the application works fine when I run by eclipse... but does not return the database data when I click on my Jar file to open the application..
    Someone can help me with that?
    I dont know if the problem is in the Spring, Hibernate, Libraries...
    thanks in advance...

    So what's the error then? Are there any error messages? Have you checked the console? Or are you just clicking on the jar and you wouldn't even see the errors if there are any?
    What do the logs say?
    You're not giving a lot to work on here.

  • Problem with Image file

    Hi,
    Iam facing with one problem.I have one swing interface through which I can upload files(back end servlet programme).Now I can upload all types of file but problem with image file it uploading perfectly that means size of the uploaded file is ok but its format damaged.It can not be open.My backend servlet programme is ok coz i tested it with html form it is working perfectly.Problem with swing interface.Plz guide me where I done a mistake.Below r my codes:-
    ImageIcon Upload=new ImageIcon("images/Upload.gif");
         Button=new JButton(Upload);
         Button.setToolTipText("Upload");
    Button.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent e)
              int returnVal = fc.showOpenDialog(ActionDemo4.this);
              if (returnVal == JFileChooser.APPROVE_OPTION) {
              File file = fc.getSelectedFile();
    String aa=file.getAbsolutePath();
              textArea3.append(aa);
                   textArea2.append("Local URL:");
    long l=file.length();
              try
              byte buff[]=new byte[(int)file.length()];
              InputStream fileIn=new FileInputStream(aa);
              int i=fileIn.read(buff);
              String conffile=new String(buff);
              String str1=textArea10.getText();
    url = new URL ("http://127.0.0.1:7001/servletUpload?x="+str1);
         urlConn = url.openConnection();
         urlConn.setDoInput (true);
         urlConn.setDoOutput (true);
         urlConn.setUseCaches (false);
         urlConn.setRequestProperty("Content-Type","multipart/form-data;boundry=-----------------------------7d11e410e500f2");
         printout = new DataOutputStream (urlConn.getOutputStream ());
    String content ="-----------------------------7d11e410e500f2\r\n"+"Content-Disposition: form-data;"+"name=\"upload\"; filename=\""+aa+"\"\r\n"+"Content-Type: application/octet-strem\r\n\r\n\r\n"+conffile+"-----------------------------7d11e410e500f2--\r\n";
    printout.writeBytes(content);
    printout.flush ();
    printout.close ();
    Best Regards
    Bikash

    The errors are here:
              byte buff[]=new byte[(int)file.length()];
              InputStream fileIn=new FileInputStream(aa);
              int i=fileIn.read(buff);
              String conffile=new String(buff); (conffile is a String object containing the image)
    and here:
    String content ="-----------------------------7d11e410e500f2\r\n"+"Con
    ent-Disposition: form-data;"+"name=\"upload\";
    filename=\""+aa+"\"\r\n"+"Content-Type:
    application/octet-strem\r\n\r\n\r\n"+conffile+"--------
    --------------------7d11e410e500f2--\r\n";
    printout.writeBytes(content);conffie is sent to the server but
    it's non possible to treat binary data as String!
    Image files must be sent as byte[] NOT as String ......

Maybe you are looking for

  • Stills from QuickTime movie

    I have been attempting to collect stills from QT movies and find they all have horizontal lines impairing the images. Is there any way to avoid this ? Many thanks.

  • How do I copy music and apps from iTouch to iTunes; PC crashed.

    My wife gave me my itouch for father's day- go wife!  But the old PC that I synced it to crashed; I did not create a backup.  I will in the future.  How do I back up all the music and apps on the itouch to iTunes?  I already searched to no avail. Alr

  • Contact Picture Size for iPhone Calls (4S, iOS 6.1.1)

    I recently updated to iOS 6.1, and even more recently to 6.1.1.  My problem is when I receive a phone call, the contact's picture is now full screen. Previously, it was a thumbnail size picture in the top right area of the screen.  I much rather pref

  • Bdc code to changing purchase group in the BOM component

    Hi We need to change the purchase grroup in the BOM comoponent level for multi level BOM's. Can we use CSAP_BOM_ITEM_MAINTAIN. any body having sample code for this...... Thanks in advance.

  • Embedded Pictures Not Showing

    When I receive mail with embedded pictures, sometimes they do not show. I just logged into the webmail for my provider, and everything shows perfectly in the mail. In Mail, there are no attachments in this latest E-mail, but my webmail shows all of t