• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Manifest/.jar Trouble

 
Greenhorn
Posts: 22
Opera Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone. I'm trying to make an executable .jar file, but cannot seem to figure out the manifest. I've Googled, checked java.sun.com, and checked recent topics here, but haven't figured it out yet. I'll start with all the information about the files:
*I have HelloWorld.class, HelloWorld.java, and HelloWorld.ctxt all in A:\Hello . The class runs fine in the editor I'm using, BlueJ. HelloWorld.class just prints "Hello World" within the public static void main(String[]args).

I'm trying to create the .jar file using MS-DOS and would like to succeed at that before trying Eclipse or another program. I have added the necessary files to the System Path, and overcome that obstacle. Here is what I am trying in MS-DOS:
1. Change directory to A:\Hello
2. Create manifest file by typing 'echo Main-Class: HelloWorld >manifest.txt'
3. Create .jar file by typing 'jar cvmf manifest.txt HelloWorld.jar HelloWorld.class'

I then try to run the .jar. When I type HelloWorld.jar in the command prompt or double-click the .jar from Windows Explorer, I get the error 'Could not find the main class. Program will exit.' When I type java -jar HelloWorld.jar I get the error 'Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld'. I'm lost as to what to do, but I think it's with the manifest file. I've tried the following modification:

1. Adding 'ClassPath: .\Hello.jar' at the beginning of the manifest file using notepad. I don't think this is necessary, as the manifest file is in the same directory as the class file, but I'm not sure. However, when I create the Manifest file using notepad, I get the error 'java.io.IOException: invalid header name: (unusual characters)Main-Class at...'.

To summarize, the main problem is that I cannot figure out the error 'Could not find the main class. Program will exit.' I think this is being caused by an error I am making in the manifest file; my second guess is it has something to do with how I have the files set up in the directories.

Thanks alot. This has me bamboozled.

Thomas Kiersted
 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/view?JarFiles
 
Thomas Kiersted
Greenhorn
Posts: 22
Opera Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I noticed that FAQ and entered 'jar cvf Hello.jar HelloWorld.class' as it suggested. However, when I then attempted to run the file Hello.jar, I received the error:

'Failed to load Main-Class manifest attribute from A:\HELLO\Hello.jar'
with the header 'Java Virtual Machine Launcher'

I expected that entering 'jar cvf Hello.jar HelloWorld.class' would correctly create the .jar file and only tried to add a manifest afterwards. I still do not understand why this is not working or how to fix it. Is a manifest file required if there is only one class? If not, why isn't the above line working? If so, why did the manifest file I created with the echo line not work?

Thomas Kiersted
 
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just manually create a file callled manifest.txt

and inside the file type:

Main-Class: <your class name here(with out .class ext)

and a couple of returns, it will error with out returns.

and put this file in the same directory of the file that you want to
jar.

and in command prompt do the following

get in the desired directory, example:

C:\documents and setting\owner> cd desktop\myjavafiles

C:\documents and settings\owner\desktop\myjavafiles> jar cmf manifest.txt myfirstjar.jar one.class two.class three.class

then your jar file is created!

now if you dont have an executable class such as "GUI" the file wont execute when you double click on it. you'll have to open it through cmd

by the way..

when you type cmf

you declaring that you want to

1. c - create a jar file
2. m - include a manifest you created
3. f - followed by the files you want to add

you MUST do it in that order, and dont forget to put the name of the
desired jar file after the manifest.txt, Example:

myfirstjar.jar

Justin
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
v - stands for verbose output.

this means that it will list the files that are zipped and the size of them
as it adds them to the .jar file

the reason you're getting the mainclass error is because you dont have a manifest included which tells the jar which class to execute as main.

cmf is what you need

jar cmf manifest.txt helloworld.jar helloworld.class

now if helloworld isn't a gui, it wont run on double click,
you'll have to run it through cmd.

jar -jar helloworld.jar
or it might be:
java -jar helloworld.jar

Justin
 
Thomas Kiersted
Greenhorn
Posts: 22
Opera Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. Unfortunately it still is not working. I'll probably download Eclipse or another Java editor at some point and try creating a .jar file with that. The create jar command from my current one, BlueJ, didn't create But just in case there is some evident error I'm missing, here are the full contents of the files I'm working with:
1/2. A:\Java\Hi.class - This is the only class in the directory. There also is a Hi.java file. Hi.java contains:

public class Hi
{
public static void main(String[] args)
{
System.out.println("Hi!");
}
}


3. manifest.txt. It contains "Main-Class: Hi" (no quotes) followed by five carriage returns.

So I went into cmd.exe. Here is what I typed/what it replied with


A:\Java>dir
Volume in drive A has no label.
Volume Serial Number is 0000-0000

Directory of A:\Java

02/26/2007 04:27 PM <DIR> .
02/26/2007 04:27 PM <DIR> ..
02/26/2007 04:42 PM 105 Hi.java
02/26/2007 04:42 PM 501 Hi.class
02/26/2007 04:33 PM 24 manifest.txt
3 File<s> 630 bytes
2 Dir<s> 219,648 bytes free

A:\Java>jar cvmf manifest.txt hi.jar hi.class
added manifest
adding: hi.class<in = 501> <out = 317><deflated 36%>

A:\Java>hi.jar

A:\Java> (it is right after this appeared that the Java Virtual Machine error above appeared it a Windows message box)


It occured to me that an unintended character may be in the manifest.txt file. Thus, I checked this:


A:\Java>edlin A:\Java\manifest.txt
End of input file
*L
1:*Main-Class: Hi
2:
3:
4:
5:
//I think this is how it should display, unless the asterisk in line 1 shouldn't be there.
*q
Abort edit?y
A:\Java>



Another check on A:\Java>dir resulted only in an entry of 786 hi.jar being added.

I've tried a few variants on this, but if the error isn't in the above I don't think I'll be able to fix it other than in person. If I made an egregious error up there, thanks for the alert. If not, eventually I'll try it in Eclipse or something like that.

Thanks again

Thomas Kiersted
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thomas Kiersted wrote:Hello everyone.  I'm trying to make an executable .jar file, but cannot seem to figure out the manifest.  I've Googled, checked java.sun.com, and checked recent topics here, but haven't figured it out yet.  I'll start with all the information about the files:
*I have HelloWorld.class, HelloWorld.java, and HelloWorld.ctxt all in A:\Hello .  The class runs fine in the editor I'm using, BlueJ.  HelloWorld.class just prints "Hello World" within the public static void main(String[]args).

I'm trying to create the .jar file using MS-DOS and would like to succeed at that before trying Eclipse or another program.  I have added the necessary files to the System Path, and overcome that obstacle.  Here is what I am trying in MS-DOS:
1. Change directory to A:\Hello
2. Create manifest file by typing 'echo Main-Class: HelloWorld >manifest.txt'
3. Create .jar file by typing 'jar cvmf manifest.txt HelloWorld.jar HelloWorld.class'

I then try to run the .jar.  When I type HelloWorld.jar in the command prompt or double-click the .jar from Windows Explorer, I get the error 'Could not find the main class.  Program will exit.'  When I type java -jar HelloWorld.jar I get the error 'Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld'.  I'm lost as to what to do, but I think it's with the manifest file.  I've tried the following modification:

1. Adding 'ClassPath: .\Hello.jar' at the beginning of the manifest file using notepad.  I don't think this is necessary, as the manifest file is in the same directory as the class file, but I'm not sure.  However, when I create the Manifest file using notepad, I get the error 'java.io.IOException: invalid header name: (unusual characters)Main-Class at...'.

To summarize, the main problem is that I cannot figure out the error 'Could not find the main class.  Program will exit.'  I think this is being caused by an error I am making in the manifest file; my second guess is it has something to do with how I have the files set up in the directories.

Thanks alot.  This has me bamboozled.

Thomas Kiersted



Hi

please follow the  following procedure for creation of jar (an example java application prog is also enclosed

Just try and find out and reply

jar -cvmf manifest.txt nalam.jar nalam/*

added manifest
adding: nalam/AlaCarte.class(in = 3930) (out= 2266)(deflated 42%)
adding: nalam/AlaCarte.java(in = 4295) (out= 1442)(deflated 66%)

java -jar nalam.jar
your manifest.txt file should contain
*********************

Main-Class: nalam.AlaCarte

********************************





 
Get off me! Here, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic