/////////////////////////////////////////////
make .jar runnable
//////////////////////////////////////////
Hello;
I can make a .jar from my program and move it to a folder in my progject but I would like to make
it runnable. So I have shown the Command to make the -cmf (non runnable) .jar that
works fine.
I will show the myManifest for the -cvmf (runnable) command but it will not load
the attribute from schoolofdb.jar.

I thought the attribute would be found in the myManifest.mf shown below.
the schoolofdb.jar is created as before but not runnabale. please find the error
stated below.

thanks
working -cmf command works fine

C:\Program Files\Java\jdk1.6.0_11\bin>jar -cvmf C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\schooldb_project\target_schooldb\schooldb\schoolofdb\myManifest.mf C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\schooldb_project\target_schooldb\schooldb\schoolofdb\test\schoolofdb.jar C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\schooldb_project\target_schooldb\schooldb\schoolofdb

-cmvf command will not load

jar -cvmf C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\schooldb_project\target_schooldb\schooldb\schoolofdb\myManifest.mf C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\schooldb_project\target_schooldb\schooldb\schoolofdb\test\schoolofdb.jar C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\schooldb_project\target_schooldb\schooldb\schoolofdb

above 3 params

jar -cvmf C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\schooldb_project\target_schooldb\schooldb\schoolofdb\myManifest.mf 

C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\schooldb_project\target_schooldb\schooldb\schoolofdb\test\schoolofdb.jar

 C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\schooldb_project\target_schooldb\schooldb\schoolofdb

b]myManifest.mf this is the only thing in the myManifest[/b]

main.class=view.main

b]error when trying to click the schoolofdb.jar created using -cvmf [/b]

Failed to load Main-Class mnifest attribute from
C:\Users\depot\Documents\ceyesumma\java-cach\my_projects\schoolofdb_project\targetPcchoolofdb\schooldb\schoolofdb\test\schoolofdb.jar

Recommended Answers

All 22 Replies

Your manifest contents looks wrong.
Here's one that works for me:

Main-Class: SlideShow.ImgIdxEditor
Class-Path: DocumentViewerWParser.jar

i just have in my manifest file:

Main-Class: multiframe


Be sure to hit enter after that line. multiframe.java contains my main class.

Mike

Also your jar command may not be right. here is a simple example. you navigate to a directory in dos window. all your java class files and manifest are in there. nothing else. your main class is like mine above, in multiframe.java. at this folder you could type java multiframe.


To jar it you would type jar cvfm program-name.jar manifest.txt *.*

two things to note. program-name.jar comes after cvfm and before manifest file name.

second thing is you are only jaring it looks like a folder. maybe you need to be in that folder and get *.class files in the jar at lease. What you jar should when unpacked run by typing java <name in manifest>

Mike

Thanks I will try that. I just read this: is this a different subject?

Creating a Manifest for a JAR File 
A manifest for a JAR file can only be created from an input stream. This example creates a manifest from a file and from a constructed string. The format of a manifest is described in: 
COPY
http://java.sun.com/products/jdk/1.2/docs/guide/jar/manifest.html
COPY
try {
    // Create a manifest from a file
    InputStream fis = new FileInputStream("manifestfile");
    Manifest manifest = new Manifest(fis);


    // Construct a string version of a manifest
    StringBuffer sbuf = new StringBuffer();
    sbuf.append("Manifest-Version: 1.0\n");
    sbuf.append("\n");
    sbuf.append("Name: javax/swing/JScrollPane.class\n");
    sbuf.append("Java-Bean: True\n");

    // Convert the string to a input stream
    InputStream is = new ByteArrayInputStream(sbuf.toString().getBytes("UTF-8"));

    // Create the manifest
    manifest = new Manifest(is);
} catch (IOException e) {
}
Here's an example of a manifest file: 
COPY
Manifest-Version: 1.0
Specification-Title: Java Platform API Specification
Specification-Version: 1.4
Implementation-Title: Java Runtime Environment
Implementation-Version: 1.4.0-rc
Created-By: 1.4.0-rc (Sun Microsystems Inc.)
Implementation-Vendor: Sun Microsystems, Inc.
Specification-Vendor: Sun Microsystems, Inc.

Name: javax/swing/JScrollPane.class
Java-Bean: True

Name: javax/swing/JCheckBoxMenuItem.class
Java-Bean: True

Name: javax/swing/JTabbedPane.class
Java-Bean: True

Name: javax/swing/JMenuItem.class
Java-Bean: True

Name: javax/swing/JTable.class
Java-Bean: True

is this a different subject?

Yes, you don't need all that for a simple executable jar file.

Hello Mike:
I am not sure on the whole proccess yet but here is what I have so far:


I have another program 'Guitar Master'.I need to create this .jar gm.jar. and make it
executable.
then put this gm.jar inside the package of of 'Guitar Master' program. I have to be able to run the program when the client puts the disk in thier computer (not sure yet) I am having trouble understanding how to run any program outside of netbeans.

but if the program runs its first job is to take the gm.jar and put it on the clients
C:\ in the folder the program already creates. Also, it should create or put an icon on the
desktop so as to run the gm.jar .exe (pending).

The 'Guitar Master' program itself runs good. In need to install it.

using the command line-not java
the command below deminstates that using the command line does almost the same
thing. It just creates a .jar of something ?? found in the program package and
creates and puts a gm.jar on the C:\ in the gmFolders dir as planned.

this is the command and resultS:

C:\Program Files\Java\jdk1.6.0_11\bin>jar -cvmf C:\Users\depot\Documents\ceyesum
ma\java_cache\my_projects\guitar_master_project\target_guitar_master\guitar_mast
er\guitar_master\build\classes\view\myManifest.txt C:\Users\depot\.gmFolders\gm.
jar C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\guitar_master_proj
ect\target_guitar_master\guitar_master\guitar_master\build\classes\view\Main.cla
ss
added manifest
adding: C:/Users/depot/Documents/ceyesumma/java_cache/my_projects/guitar_master_
project/target_guitar_master/guitar_master/guitar_master/build/classes/view/Main
.class(in = 944) (out= 584)(deflated 38%)

C:\Program Files\Java\jdk1.6.0_11\bin>jar -cvmf C:\Users\depot\Documents\ceyesum
ma\java_cache\my_projects\guitar_master_project\target_guitar_master\guitar_mast
er\guitar_master\build\classes\view\myManifest.txt C:\Users\depot\.gmFolders\gm.
jar C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\guitar_master_proj
ect\target_guitar_master\guitar_master\guitar_master\build\classes\view\Main.cla
ss
[b]added manifest[/b]
adding: C:/Users/depot/Documents/ceyesumma/java_cache/my_projects/guitar_master_
project/target_guitar_master/guitar_master/guitar_master/build/classes/view/Main
.class(in = 944) (out= 584)(deflated 38%)

C:\Program Files\Java\jdk1.6.0_11\bin>

Whether or not this is even close my main concern is that the jar created
is not executable it finds the myManifest.txt but can not load the attribute

Failed to load Main-Class.mnifest attribute from
C:\Users\depot\.gmFolders\gm.jar

the Main.class and the myManifest.txt are in the same folder

//////////

//////////
path to dest
//////////
C:\Users\depot\.gmFolders\gm.jar

//////////
path to myManifest.txt
////////////

C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\guitar_master_project\target_guitar_master\guitar_master\guitar_master\build\classes\view\myManifest.txt

////////
path to classes
///////////
////
C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\guitar_master_project\target_guitar_master\guitar_master\guitar_master\build\classes\view\Main.class

///////

myManifest.txt

Main-Class: Main

What is in the jar file you create? Open it and look at its contents. On windows, you can rename it by adding .zip at the end of the filename and use the windows utility.
Verify that the manifest file is there(should be in the meta-inf folder) and that the Main.class file is there and that they are in the correct "folders".
Is the Main class in a package?

What errors do you get when you try to execute the jar file by using the command:
java -jar gm.jar

Copy and paste them here.
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.

Thanks Mike I have no ie connection for a while. I will try this when I can get to my computer. I will get back to you.

incedentally the reacurring error is posted already and as far as I know the myManifest.txt (why that is not myManifest.MF I'm not sure) is in the build \clssses\view package of the project along side of the Main.class
NetBeans packages it something like that but the class file is in whith the mainfest
at the URL noted.

Is researching Java Installation tutorial a good choice to under stand this?
thanks again.

What errors do you get when you try to execute the jar file by using the command:
java -jar gm.jar

Copy and paste them here.
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.

############################# results #####################################33

C:\Program Files\Java\jdk1.6.0_11\bin>jar -cvmf C:\Users\depot\Documents\ceyesum
ma\java_cache\my_projects\guitar_master_project\target_guitar_master\guitar_mast
er\guitar_master\build\classes\view\myManifest.txt C:\Users\depot\.gmFolders\gm.
jar C:\Users\depot\Documents\ceyesumma\java_cache\my_projects\guitar_master_proj
ect\target_guitar_master\guitar_master\guitar_master\build\classes\view\Main.cla
ss
added manifest
adding: C:/Users/depot/Documents/ceyesumma/java_cache/my_projects/guitar_master_
project/target_guitar_master/guitar_master/guitar_master/build/classes/view/Main
.class(in = 944) (out= 584)(deflated 38%)

C:\Program Files\Java\jdk1.6.0_11\bin>
C:\Program Files\Java\jdk1.6.0_11\bin>jar tvf C:\Users\depot\.gmFolders\gm.jar
     0 Fri Aug 13 22:41:10 CDT 2010 META-INF/
    71 Fri Aug 13 22:41:10 CDT 2010 META-INF/MANIFEST.MF
   944 Tue Aug 10 21:19:08 CDT 2010 C:/Users/depot/Documents/ceyesumma/java_cach
e/my_projects/guitar_master_project/target_guitar_master/guitar_master/guitar_ma
ster/build/classes/view/Main.class


C:\Program Files\Java\jdk1.6.0_11\bin>

I still have to change he extention and try to unzip it.

This does something but I do not know where to find what ever it did
it was supposed to unpack something and put the files in the current dir

C:\Program Files\Java\jdk1.6.0_11\bin>jar -xf C:\Users\depot\.gmFolders\gm.jar

C:\Program Files\Java\jdk1.6.0_11\bin>

running is missing the attribute im myManifet
myManifest.txt

Main-Class: Main

running is missing the attribute im myManifet

C:\Program Files\Java\jdk1.6.0_11\bin>java -jar C:\Users\depot\.gmFolders\gm.jar

Failed to load Main-Class manifest attribute from
C:\Users\depot\.gmFolders\gm.jar

C:\Program Files\Java\jdk1.6.0_11\bin>

The file says it is .exe but it still isn't. Do I have to mess with a class path?
will have to take it out of Netbeans to run it with my own manifest?

I get the following when using -jar option on a jar file without Main-Class: in manifest.

D:\JavaDevelopment>java -jar acme.jar
Failed to load Main-Class manifest attribute from
acme.jar

Open your jar file (or extract all its contents) and look at the manifest file.

One weird thing about the contents of the manifest file: all lines MUST end with a newline character.

I will have to do that and do some additional .jar command research
newbie question:
I have not compliled a program in so long( using netbeans)
if I have all the class files in with my manifest and all the main starts the chain
of imports for the whole program (anywhere from 40 60 131 classes)
then It will compile? I let netbeans handle all that so I am not sure if I will
have to extract all my classes and because I do not know how to run the thing.

Sorry, I don't know how to use your IDE.

If the manifest file is correct and the Main-Class: points to the Main class in the gm.jar file then the command:
java -jar gm.jar
should start the execution of the Main class. After that what happens depends on if the java program can find the other classes it needs in the jar file.

I still don't have the contents of the guitar_master.jar I still need to change the .zip extention and extract it.

Failed to load Main-Class.mnifest attribute fromC:\Users\depot\.gmFolders\gm.jarFailed to load Main-Class.mnifest attribute from
C:\Users\depot\.gmFolders\gm.jar

What did you just post? I don't recognize the format of the message.
Is there more to the message that you have left off?

What do you do to get that message?

That is a dialog box
but the dos messages is the same:

C:\Program Files\Java\jdk1.6.0_11\bin>java -jar C:\Users\depot\.gmFolders\gm.jar Failed to load Main-Class manifest attribute fromC:\Users\depot\.gmFolders\gm.jar C:\Program Files\Java\jdk1.6.0_11\bin>C:\Program Files\Java\jdk1.6.0_11\bin>java -jar C:\Users\depot\.gmFolders\gm.jar

Failed to load Main-Class manifest attribute from
C:\Users\depot\.gmFolders\gm.jar

C:\Program Files\Java\jdk1.6.0_11\bin>

Can you extract the contents of the jar file and look at the manifest file?
the java program does not like it for some reason.

My ie connection and program are in two seperate places for a minute.

I have the contens though:

Main-Class: Main

I am using netbeans to create the program and it has MANIFEST.MF and I do not know if I have to take all my stuff out and use myManifest.MF to get it to work.

any way the myManifest.txt is in the same folder that the Main.class is in with the above contents and i get the errror mentioned that states that it can not load an attribute.
Thanks for the help.

If that is the contents of the manifest file that is IN THE jar file. It looks OK. Is there a newline character after Main? ie did you press Enter after typing Main?

myManifest.txt is in the same folder that the Main.class is in

No that is wrong. The manifest file should be in the meta-inf folder in the jar file.

MusicSys:unsolved:

notning is in the .zip

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.