Icons disappear when creating a jar file.

I am trying to make a runable jar file of an application that i wrote however, when i export it from eclipse the icons no longer appear. All of the icons are contained in a class called gridGui. Any help would be great.
Thanks
     //Creates all of the icon files used for the buttons
     Icon fiftyCents = new ImageIcon("Fifty_Cents.gif");
     Icon oneDollar = new ImageIcon("One_Dollar2.gif");
     Icon twoDollar = new ImageIcon("Two_Dollar.gif");
     Icon threeDollar = new ImageIcon("Three_Dollar.gif");
     Icon fiveDollar = new ImageIcon("Five_Dollar.gif");
     Icon tenDollar = new ImageIcon("Ten_Dollar.gif");
     Icon freePlay = new ImageIcon("Free_Play.gif");
     Icon blank = new ImageIcon("Blank.gif");
     Icon unflipped = new ImageIcon("UnFlipped.gif");
     Icon oneDollarCoupon = new ImageIcon("One_Dollar_Coupon.gif");
     Icon threeDollarCoupon = new ImageIcon("Three_Dollar_Coupon.gif");
     Icon tShirt = new ImageIcon("TShirt.gif");
     Icon youLose = new ImageIcon("You_Lose.gif");

You are using the ImageIcon constructor that takes a file name argument. When you create the jar file the source for the images are no longer files but entries in your jar file. You have to access them using the ImageIcon constructor that takes a URL argument.
The actual URL you use is obtained (eg) from the Class method [getResource()|http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResource(java.lang.String)].
Suppose your Fifty_Cents.gif was in your jar file in the folder "images" then you could say:
Icon fiftyCents = new ImageIcon(getClass().getResource("/images/Fifty_Cents.gif");Note the use of forward slashes and the fact that Fifty_Cents.gif has to be capitalised exactly as it is within the jar file.
There are other ways of organising the resources - see the getResource() documentation for details.

Similar Messages

  • When creating a jar file

    Whenever I add a "Contributor" to the jar file it fails to locate the Main Class that I have specified. What am I doing wrong

    User, is doesn't help to open a new topic without giving any more information. In your other thread {message:id=9844156} we got more info and are waiting for your replay.
    Timo

  • I am getting system tray icon when i execute jar file.

    Hi.,
    I am not getting system tray icon when i execute jar file. But a process is created and its running at background... When i execute the same program in net beans, i got system tray icon as well. why i didn't get system tray icon outside the net beans.? Can anyone help me on this..?????

    Karthik_Java wrote:
    Hi.,
    I am not getting system tray icon when i execute jar file. But a process is created and its running at background... When i execute the same program in net beans, i got system tray icon as well. why i didn't get system tray icon outside the net beans.? Can anyone help me on this..?????What version of the JRE is set as the default on your machine, as far as I'm aware the ability to crap up the notification area was only added in JSE6.

  • Created PDF form in Acrobat XI Pro, but HELP fields disappear when I save FCDT file to PDF. Please help. Thanks!

    Created PDF form in Acrobat XI Pro, but HELP fields disappear when I save FCDT file to PDF. Please help. Thanks!

    I am not aware of a field type "Help" within a PDF form. I do not see it as a form field that can be added in the form edit mode.
    Forms Central forms do not support all the features of Acrobat forms.
    Are you talking about the "Tool Tips" or a hidden field that only shows when one enters a field and is hidden upon exiting the field.

  • Creating a manifest.mf when generating a jar file.

    First post ever using java and its probable really simple. I've basically been chucked in at the deep end of a java app. I've had to reverse engineer it and I'm at the following stage:-
    I'm rebuilding the project to create my jar file and I'd like to
    1)get a list of all the files of the project within my manifest.mf
    2)Digitally sign the files as well, which from what I've read create a *.DSA and *.SF file. The manifest would then have to contain the checksums (SHA1-Digest)
    Now I've been playing for a few hours trying to get the manifest to produce the list of files, but with no success all I get is teh default.
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.6.5
    Created-By: 1.5.0_12-b04 (Sun Microsystems Inc.)Any ideas on what I'm missing.
    Thanks for any help it will be greatly appricated by a newb with 0% java experience
    (taking me a few days to sort out a Ubuntu server to serve the Java apps, but thats working sweet as :D)

    got it all working in the end.
    Used the following within the jdk/bin folder
    keytool - to create a cert
    jar - to create the jar file
    jarsigner - to create the manifest and sign the files.
    I created a load of bat files to do the job.
    Now onto the next problem of compiling the java files into class's

  • What is the command to create a jar file through Command Promt?

    Hi,
    I done my java project. Now i need to create a exe or jar file to fully complete it. I decided to create a jar file. Because, It'll support both PC and MAC. I exported my JAR file through eclipse. But that jar file loads without images and icons when it is in other directory. How can i include images folder in a JAR File.
    For ex:
    I have parent folder named "Support". Under this there is 3 subfolder namely
    bin - Classes
    src - java files
    images - image files.
    I need to create jar file to "Support" folder which should contain all the above mentioned sub folders.
    I need to execute this jar file anywhere which should not depend on the above mentioned folders which mean adding the images folder in that created jar file.
    Pls guide me for this problem.
    Thanks in advance
    Regards,
    Mohan

    But that jar file loads without images and icons when it is in other directory.Images should be accessed via a URL rather than using a filename because they will exist as entries in the jar archive not as files. Typically this URL would be obtained by using the Class method [getResource()|http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResource(java.lang.String)]. There are details in this [Java World article|http://www.javaworld.com/javaworld/javaqa/2002-11/02-qa-1122-resources.html].

  • I Can't Create my jar File

    I have a package called voiceexpert which contains three classes: Disease, DiagnosingEngine and Symptoms which is a JavaBean. Symptoms makes use of Disease and DiagnosingEngine objects.
    voiceexpert is stored in the directory: c:\diagapp3
    I compiled Symptoms.java as below:
    c:\diagapp3> javac -d . Symptoms.java
    The class files for Disease.java, DiagnosingEngine.java and Symptoms.java are placed in the directory: voiceexpert.
    I created a Manifest.txt file inside c:\diagapp3 containing the following:
    Main-Class:voiceexpert.voiceexpert.Symptoms
    Name:voiceexpert/Symptoms.class
    Java-Bean:True
    I later created the jar file with the command:
    jar cfm jjj.jar Manifest.txt voiceexpert\*.*
    But, I am having the error message: "*invalid header field*".
    What can I do to remove this error?
    Note: I created the Manifest.txt using utf-8 encoding. My code is to be used in a third-party application and that is why it does not contain a main method.
    The link I was referred to could not help me. I need help please!
    Edited by: Adeyi on Feb 24, 2010 2:26 AM
    Edited by: Adeyi on Feb 24, 2010 2:34 AM

    Adeyi wrote:
    ..I created a Manifest.txt file inside c:\diagapp3 containing the following:
    Main-Class:voiceexpert.voiceexpert.Symptoms
    Note: I created the Manifest.txt using utf-8 encoding. My code is to be used in a third-party application and that is why it does not contain a main method.Why are you specifying a main-class when the API has none?
    The link I was referred to..What link? Just imagine for the moment that the Internet is a big place and we are not psychic.

  • Problem in Creating a jar file using java.util.jar and deploying in jboss 4

    Dear Techies,
    I am facing this peculiar problem. I am creating a jar file programmatically using java.util.jar api. The jar file is created but Jboss AS is unable to deploy this jar file. I have also tested that my created jar file contains the same files. When I create a jar file from the command using jar -cvf command, Jboss is able to deploy. I am sending the code , please review it and let me know the problem. I badly require your help. I am unable to proceeed in this regard. Please help me.
    package com.rrs.corona.solutionsacceleratorstudio.solutionadapter;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.util.jar.JarEntry;
    import java.util.jar.JarOutputStream;
    import java.util.jar.Manifest;
    import com.rrs.corona.solutionsacceleratorstudio.SASConstants;
    * @author Piku Mishra
    public class JarCreation
         * File object
         File file;
         * JarOutputStream object to create a jar file
         JarOutputStream jarOutput ;
         * File of the generated jar file
         String jarFileName = "rrs.jar";
         *To create a Manifest.mf file
         Manifest manifest = null;
         //Attributes atr = null;
         * Default Constructor to specify the path and
         * name of the jar file
         * @param destnPath of type String denoting the path of the generated jar file
         public JarCreation(String destnPath)
         {//This constructor initializes the destination path and file name of the jar file
              try
                   manifest = new Manifest();
                   jarOutput = new JarOutputStream(new FileOutputStream(destnPath+"/"+jarFileName),manifest);
              catch(Exception e)
                   e.printStackTrace();
         public JarCreation()
         * This method is used to obtain the list of files present in a
         * directory
         * @param path of type String specifying the path of directory containing the files
         * @return the list of files from a particular directory
         public File[] getFiles(String path)
         {//This method is used to obtain the list of files in a directory
              try
                   file = new File(path);
              catch(Exception e)
                   e.printStackTrace();
              return file.listFiles();
         * This method is used to create a jar file from a directory
         * @param path of type String specifying the directory to make jar
         public void createJar(String path)
         {//This method is used to create a jar file from
              // a directory. If the directory contains several nested directory
              //it will work.
              try
                   byte[] buff = new byte[2048];
                   File[] fileList = getFiles(path);
                   for(int i=0;i<fileList.length;i++)
                        if(fileList.isDirectory())
                             createJar(fileList[i].getAbsolutePath());//Recusive method to get the files
                        else
                             FileInputStream fin = new FileInputStream(fileList[i]);
                             String temp = fileList[i].getAbsolutePath();
                             String subTemp = temp.substring(temp.indexOf("bin")+4,temp.length());
    //                         System.out.println( subTemp+":"+fin.getChannel().size());
                             jarOutput.putNextEntry(new JarEntry(subTemp));
                             int len ;
                             while((len=fin.read(buff))>0)
                                  jarOutput.write(buff,0,len);
                             fin.close();
              catch( Exception e )
                   e.printStackTrace();
         * Method used to close the object for JarOutputStream
         public void close()
         {//This method is used to close the
              //JarOutputStream
              try
                   jarOutput.flush();
                   jarOutput.close();
              catch(Exception e)
                   e.printStackTrace();
         public static void main( String[] args )
              JarCreation jarCreate = new JarCreation("destnation path where jar file will be created /");
              jarCreate.createJar("put your source directory");
              jarCreate.close();

    Hi,
    I have gone through your code and the problem is that when you create jar it takes a complete path address (which is called using getAbsolutePath ) (when you extract you see the path; C:\..\...\..\ )
    You need to truncate this complete path and take only the path address where your files are stored and the problem must be solved.

  • How to create a .jar file for the BPEL project

    hi all,
    how can i create a .jar file for my BPEL project, i am trying to deploy the project but getting an error :
    "Error: [Error ORABPEL-10902]: compilation failed [Description]: in "C:\OraBPELPM\integration\jdev\jdev\mywork\Workspace_BPELDemo\BPEL_Report\BPEL_Report.bpel", XML parsing failed because "". [Potential fix]: n/a. "
    and when doubel cliking on this error Jdev take me to the beginning of the ".bpel" file.
    I 'm really stuck in here i am not able to deploy the process!
    Thanks,
    Rana

    Rana:
    If you haven't already, I would post this question in the BPEL forum. I would expect a much better turnaround there.
    Johnny Lee

  • How can I create a jar file at a Unix systems?

    Hi there,
    how what's the command to create a jar file in Unix? I'm creating a zip file and then renaming it to jar, but it's size is smaller than the one when I use the WinZip tool at a Windows system.
    Thanks,
    Andre

    Oops,
    it very easy to do. Just use the jar -cvf command
    Andre

  • Create a jar file using the jar tool

    Hello all,
    can somebody help me with this situation:
    I use the following comand
    jar cfm Seti.jar manifest.mf SetiSeti.jar is the name of the file I want to create and Seti is the name of the folder where I have the class files, the manifest file and the Seti.java. The manifest file is also out of this folder (exactly the folder were I use the command on the command line).
    After creating the jar... I try to run it but it gives an error message: "can't find the main class..."
    The content of the manifest file is:
    "Manifest-Version: 1.0
    Main-Class: Seti
    I'd never created a jar file before and have already read all the usefull information here and at sun... I'm very preoccupied with this..
    Can you help?
    Thanks

    RuiAranhaJava wrote:
    How do I do this?
    "And you have to name that package as well when you name the main class in the manifest. "
    But, as I have told the name of the package is SetiNo, you just told us that the name of your class is Set. You never told us about the name of the package.
    Simples question possible: Does your class look something like this:
    package Seti;
    // maybe there are some import statements here, maybe not
    public class Seti {
      // maybe there's something here, maybe not
      public static void main(String[] args) {
        // anything
    }If so, then the fully qualified name of your class is "Seti.Seti" and you need to write that into the Main-Class attribute. (*)
    If there is no package-Statement, then the fully qualified name of your class is simply "Seti" and the Main-Class attribute is correct, but your classes are in the wrong place.
    Edit:
    (*) Please note that package names should generally be all-lowercase, so it should be "seti" instead of "Seti". This helps distinguish it from the simple names of classes, so it's easy to see what you are talking about at a glance: "seti" would be the package, "Seti" the class name.

  • Problem when modifying the jar file of a portal component

    I get the umelogonbase.jar from the com.sap.portal.runtime.logon component, extract it with winzip, do not make any changes to the source code, then re-create the jar file and add it back to the component. Now, when I deploy the component to the Portal I get the following error:
    "Portal Runtime Error
    An exception occurred while processing a request for :
    iView : N/A
    Component Name : N/A
    com/sap/security/core/logonadmin/IAccessToLogic.
    Exception id: 10:30_08/08/07_0012_15067450
    See the details for the exception ID in the log file"
    any idea what I am doing wrong here?
    I am doing this because I need to change the texts in the umelogonbase.jar, so this is the first step to see that the component still runs once I modify the jar file.
    Note: I create the jar file by creating a jar-type project in NWDS and then exporting the project as jar.

    Do you have JDK installed? If not then please install it by downloading from http://java.sun.com/j2se/1.4.2/download.html. Install it in your local machine. Then inside the installation folder\bin folder you will find the jar.exe.
    Also create the environment parameter named JAVA_HOME and set the value as the installation directory of JDK for example JAVA_HOME=C:\j2sdk1.4.2_13. Also add the following to your Path environment variable
    C:\j2sdk1.4.2_13\bin;C:\j2sdk1.4.2_13\lib;
    these path names should vary depending upon your actual JDK installation folder name.
    Regards,
    Shubho

  • Help To Create a Jar File

    hi there
    i wanna create a exe file so i am trying to use jar file.
    I am new at creating jar files, my application has a main file and other java files, i am using other java files in my main file my concern is can i create a jar file including all the files and when i run jar file i want to complie java files, i really appreciate if anyone can help me out creating a jar file to compile and execute java files

    http://java.sun.com/j2se/1.4.2/docs/guide/jar/index.html

  • Creating a jar file

    Hello all. I am trying to create a jar file for a *"hello world"* program. I compiled the code using netbeans and created the jar file from the HelloWorld.class. I added the main class to the manifest with the following line
    Main-Class: helloworld.HelloWorld
    Ensured there was a carriage return just before the end of the file.
    When I run the program I get the following error:
    h1Exception in thread "main" java.lang.NoClassDefFoundError: helloworld/HelloWorld*
    Please help

    I tried the last command it produced this error
    *C:\Documents and Settings\oshonowo\My Documents\Projects\DOS>set JAVA_HOME=c:/Pr
    ogram Files/Java/jdk1.6.0_03
    C:\Documents and Settings\oshonowo\My Documents\Projects\DOS>set classpath=C:\Pr
    ogram Files\Java\jdk1.6.0_03\lib\;C:\Program Files\Java\jre1.6.0_03\lib\ext\QTJa
    va.zip;C:\Program Files\Java\jdk1.6.0_03\jre\lib;C:\Program Files\Java\jre1.6.0_
    03\lib;%CLASSPATH%;.;C:\Documents and Settings\oshonowo\HelloWorld\build\classes
    \helloworld\Hello.jar
    C:\Documents and Settings\oshonowo\My Documents\Projects\DOS>"c:/Program Files/J
    ava/jdk1.6.0_03\bin\java" helloworld.HelloWorld
    Exception in thread "main" java.lang.NoClassDefFoundError: helloworld/HelloWorld
    C:\Documents and Settings\oshonowo\My Documents\Projects\DOS>pause
    Press any key to continue . . .*
    Please help

  • Getting error when running the jar file..

    Hi All,
    I am new to executing jar file..Actually i have one class which contains the following code.
    import com.documentum.fc.client.DfClient;
    import com.documentum.fc.client.IDfClient;
    import com.documentum.fc.client.IDfSession;
    import com.documentum.fc.client.IDfSessionManager;
    import com.documentum.fc.common.DfLoginInfo;
    import com.documentum.fc.common.IDfLoginInfo;
    import com.documentum.fc.common.DfException;
    import com.fidelity.ftg.ereviewg2.migration.util.MigrationResource;
    * This class is used for creating docbase connection
    * *@type* DocbaseConnection
    * *@author* a405304
    * *@see*
    public *class *DocbaseConnection {
    //public static ResourceBundle resource;
    IDfSessionManager sMgr = *null*;
    IDfSession session = *null*;
    String docbaseName;
    *private* *static* DocbaseConnection +docbaseCon+;
    * Constructor for DocbaseConnection
    * *@throws* DfException
    * *@throws* Exception
    *private* DocbaseConnection()*throws* DfException, Exception{
    //ResourceBundle bundle = ResourceBundle.getBundle(Constants.RESOURCE_PATH,Locale.getDefault());
    MigrationResource bundle = MigrationResource.+getBundle+();
    String userId = bundle.getString("DOCBASE_USERID");
    String password = bundle.getString("DOCBASE_PASSWORD");
    docbaseName = bundle.getString("DOCBASE_NAME");
    IDfClient client = DfClient.+getLocalClient+();
    sMgr = client.newSessionManager();
    IDfLoginInfo loginInfo = *new* DfLoginInfo();
    loginInfo.setUser( userId );
    loginInfo.setPassword( password );
    loginInfo.setDomain("");
    sMgr.setIdentity( docbaseName, loginInfo );
    session= sMgr.getSession( docbaseName );
    System.+out+.println("# Connected to Docbase: "+session);
    }Now i create the jar file whose name is docbaseconnection.jar
    Now when i am running this jar file by using the following command then i am getting the following error..
    C:\JAR_FILES>java -jar docbaseconnection.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: com/documentum/fc/client/DfQuery
    For running this docbaseconnection.jar file i need the following thing in classpath...
    C:\Program Files\Documentum\dctm.jar;C:\Program Files\Documentum\Shared\dfc.jar;C:\Program Files\Documentum\Shared\log4j.jar
    I already add this jar files in the classpath of environment variables..Then also i am getting the same error..
    Kindly help me...........

    Well, let´s supose your manifest is defined as I did in my previous post. So, your directory base should be something like:
    C:\dir
    docbaseconnection.jar
    dctm.jar
    dfc.jar
    anotherlibraries.jar
    But, let´s supose you want something like
    C:\dir
    docbaseconnection.jar
    lib (folder, which contains dctm.jar, dfc.jar, etc)
    Then you should change the class-path of your manifest to
    Class-Path: ./lib/dctm.jar ./lib/dfc.jar
    That´s what I meant

Maybe you are looking for

  • Payment terms- Ex works

    payment terms- Ex works means wat pls giv the list of payment terms and when we hav use each

  • Messages are in waiting mode in SMQ2

    Hello All, I have plenty of messages in waiting mode of SMQ2. How do I release these messages from the queues. The queue name starts with ABC* in SMQR and it is Registration mode. Please let me know step by step solution and checklist Thanks Mike

  • Jax-WS 2.2 web service instances management on Glassfish 3

    Hi all, I'm studying Jax-WS specification in general and its implementation on Glassfish 3.1.2. I built a simple standard example where a jax-ws soap based web service is called from a jsp page by using the artifacts generated through wsimport (the w

  • LMS 4.0.1 Backup Error Message

    LMS installed on Windows 2003. Backup fais with message "Backup failed.ERROR(1297): Fatal error: Database engine 'UPMDbEngine' could not be started on database 'upm' in Bulk mode.." dbbackup.log attached. Any help or explanation is greatly appreciate

  • Why wouldn't my trackpad click or scroll?

    I was browsing Facebook and listening to music on iTunes and all of a sudden my trackpad sort of locked up. I could move it around the screen just fine, but it would not scroll or click on anything. I had to press the power button (I did not hold the