Hi,i have a program and i created into a jar file,but the problem is when i am going to remove the jar file into the directory where my java classes and pictures resides,when i click the jar file the picture of my buttons are gone.can you help me please how can i make my picture visible to the jar file without putting back the jar file into the directory.or how can i generate another jar file that will include pictures.

Can you put the images, etc in the jar file? Then they would always be at the same location.
I use the jar command to add files to a jar file.

@James, i read the link,as i understand i need to include the directory of my images?but i did not put the images in the folder.my java class and images are inside in one directory.

@NormR1, I haven't tried yet to put images in the jar file,I have no idea.can you please show me how?

First read the doc for the jar command.
Then try using it to create a jar file and add files to a jar file.
Here is a batch file I use to create a jar file:

REM Make FTPUpLoader.jar file
Set JarName=%JAVA_RUN%\FTPUploader.jar 
%DEV_DRIVE%
cd %DEV_HOME%\JavaDevelopment\NormsDev\FTPUpLoader\
jar -cmf FTPUpLoader.mnf %JarName% *.class 
@REM Now pick up the Tools it needs:
cd %DEV_HOME%\JavaDevelopment\
jar -uf %JarName% NormsTools\ErrDialog*.class NormsTools\MakeEnterDoAction*.class NormsTools\MessageArea*.class NormsTools\ShowMsgBox*.class NormsTools\ChoiceOfYesOrNo*.class NormsTools\ShowListBox*.class
@ECHO --- Created %JarName% ---
MORE

Note: The uppercase named variables in %s are environment variables.

Edited 4 Years Ago by NormR1

@NormR1, Okay thank you for this okay i wil try this one.

@James, i read the link,as i understand i need to include the directory of my images?but i did not put the images in the folder.my java class and images are inside in one directory.

You will find that it's easier to update and maintain your application if you separate unchanging resources like images from the code itself. This is even more important when you start to use packages properly because they require multiple code directories. It's a very common convention to have an "images" directory that lives at the same level as the top-most code directory. I strongly recommend that you put your images in their own directory before starting to package it all into jar.

Here's the procedure on how to include a images on a java file (basic):
1. Create an Manifest file, this contain the Main class of your jar file

Manifest-Version: 1.0
Main-Class: Main

where Main is your Main-Class
2. Execute the jar command to create a jar file, explicity include your image or the directory where you image is located.

jar cmf Main.mf Main.jar Main.class Main.java public/images

in here I include on the public/images sub-directory, this directory contains all the images you can also just put public if you want to include all the sub-directory of public. You can also elaborate images that you only needed under images. This command will create a jar file by the way.

3.To valid that content of your jar file run jar tf YourJarFile.jar

jar tf Main.jar

To access the image you can use the ToolKit api like:

Image image = Toolkit.getDefaultToolkit().getImage(getClass.getResource(
"public/images/image.gif"));

@NormR1 @James,it says that

 java.io.FilenotFoundException: manifest.mf (They System cannot find the the file    specified)
 at java.io.FileInputStream.open(Native Method)
 at java.io.FileInputStream<init>(FileInputStream.java:138)
 at java.io.FileInputStream<init>(FileInputStream.java:97)
 at suns.tools.jar.Main.run(Main.java:171)
  at suns.tools.jar.Main.run(Main.java:1177)

what does it mean? but my manifest is inside the same folder of my java codes and my images.@James i put now all the images in one directory.

Edited 4 Years Ago by jemz

Can you copy and paste here the full contents of the console? also do a dir command to show the contents of the directory where you issue the jar command. The files must be accessible from the directory where you issue the jar command.

On windows To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

Edited 4 Years Ago by NormR1

@NormR1,here it is

C:\Documents and Settings\jemz\Desktop\myprog>jar cmf myManifest.mf Student.jar
GuiStudent$AddButton.Class GuiStudent$DeleteButton.Class GuiStudent$ExitButton.C
lass GuiStudent$SearchButton.Class GuiStudent.Class Student.Class StudentRecord$
2.Class StudentRecord.Class GuiStudent$ClearButton.Class GuiStudent$DisplayButto
n.Class GuiStudent$NoDataInputException.Class GuiStudent$UpdateButton.Class Pers
on.Class StudentRecord$1.Class StudentRecord$ok.Class GuiStudent.java Student.ja
va Person.java StudentRecord.java images
java.io.FileNotFoundException: myManifest.mf (The system cannot find the file sp
ecified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at java.io.FileInputStream.<init>(FileInputStream.java:97)
        at sun.tools.jar.Main.run(Main.java:171)
        at sun.tools.jar.Main.main(Main.java:1177)

C:\Documents and Settings\jemz\Desktop\myprog>

Dir...

08/22/2012  02:08 AM    <DIR>          .
08/22/2012  02:08 AM    <DIR>          ..
08/22/2012  01:42 AM             3,633 GuiStudent$AddButton.class
08/22/2012  01:42 AM               494 GuiStudent$ClearButton.class
08/22/2012  01:42 AM               570 GuiStudent$DeleteButton.class
08/22/2012  01:42 AM               580 GuiStudent$DisplayButton.class
08/22/2012  01:42 AM               512 GuiStudent$ExitButton.class
08/22/2012  01:42 AM               398 GuiStudent$NoDataInputException.class
08/22/2012  01:42 AM               577 GuiStudent$SearchButton.class
08/22/2012  01:42 AM               573 GuiStudent$UpdateButton.class
08/22/2012  01:42 AM             7,966 GuiStudent.class
08/22/2012  01:47 AM            13,899 GuiStudent.java
08/22/2012  12:49 AM    <DIR>          images
08/22/2012  02:07 AM                49 myManifest.mf.txt
05/15/2011  01:57 PM             2,453 Person.class
04/19/2011  06:17 PM             1,778 Person.java
05/15/2011  01:57 PM             2,606 Student.class
04/08/2011  09:35 PM             3,379 Student.java
08/21/2012  02:29 AM             2,760 StudentRecord$1.class
08/21/2012  02:29 AM               940 StudentRecord$2.class
04/07/2011  09:38 PM               587 StudentRecord$ok.class
08/21/2012  02:29 AM             8,040 StudentRecord.class
08/21/2012  02:29 AM            10,315 StudentRecord.java
              22 File(s)         62,192 bytes
               3 Dir(s)   8,823,861,248 bytes free

C:\Documents and Settings\jemz\Desktop\myprog>

You left off the showing the jar command and its results.

What is the following? You need to tell the OS to show you the full name of files. Do NOT hide extensions.

myManifest.mf.txt

@NormR1,

You left off the showing the jar command and its results.

I already paste it,you mean like this jar cmf etc...?

Okay i tried to change it to jar cmf myManifes.mf.txt Student.jar etc...
it created a jar file but when i click the jar file it shows nothing happen.
i also executed this command

C:\Documents and Settings\jemz\Desktop\myprog>java -jar Student.jar
Error: Could not find or load main class GuiStudent

Look in the jar file and make sure the GuiStudent class is there and is in the correct folder.
A zip utility will work for viewing a jar file.

@NormR1, yup i opened it using winrar the GuiStudent Class is there.BTW norm is this also affected in my java version i have this version

C:\Documents and Settings\jemz\Desktop\myprog>java -version
java version "1.7.0_06"
Java(TM) SE Runtime Environment (build 1.7.0_06-b24)
Java HotSpot(TM) Client VM (build 23.2-b09, mixed mode, sharing)

the GuiStudent Class is there

Is the class file in the correct folder?
Is the class in a package?
What's in the manifest file?

Edited 4 Years Ago by NormR1

@NormR1..this is what inside in manifest file

Manifest-Version: 1.0
Created-By: 1.7.0_01 (Oracle Corporation)
Main-Class: GuiStudent

You missed these 2 questions:

Is the class file in the correct folder?
Is the class in a package?

Is the file named: GuiStudent.Class or GuiStudent.class

Edited 4 Years Ago by NormR1

@NormR1..GuiStudent.Class

Yup the class file is in the correct folder

@NormR1,sorry i am having difficulties in uploading the image.

Edited 4 Years Ago by jemz

You still missed this question:

Is the class in a package?

And

GuiStudent.Class

I think it has the wrong extension name. Change the extensions to class.

Edited 4 Years Ago by NormR1

@NormR1, you mean from GuiStudent.Class to GuiStudent.class?

ahm what is.."Is the class in a package"?

@NormR1,it's working now,but i have problem when i am tring to remove the jar file in the root folder,and put it to desktop.when clicking the jar file the image of my buttons are gone..but i followed what james instructed me and basing to the link that he give to me.

@NormR1,i fixed now and it's working and i tried to remove the jar in the folder,and put it on the desktop when i clicked the jar file the image is there....lastly is it necessary to put all the classes in making the jar like this GuiStudent$DisplayButton.class,GuiStudent$ClearButton,GuiStudent$ExitButton and etc...i thought only the main class should be there.

@NormR1,Thank you so much for helping me.I hope you can still help me in other problems

@NormR1,i am trying to use the batch file that you give to me but i find difficulty to understand the command...can you help me please...is this possible not to individually put the class file...I mean that i want that when i click the batch file it will automatically get all the class and create a jar file, it this possible?

This question has already been answered. Start a new discussion instead.