• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Got an error message Failed to load Main-class manifest attribute from sampleproject.jar

 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I followed the instruction in Chapter 9 of the Monkhouse book, when I run javaw -jar sampleproject.jar alone, I got this error "Failed to load Main-Class manifest attribute from sampleproject.jar."

I have a DVD directory.
I compile DVD/src/sampleproject and put the classes in DVD/classes/sampleproject
I created Manifest.mf file and specify the main class is in sampleproject.gui.ApplicationRunner
Under DVD directory, I type jar -cfm sampleproject.jar Manifest.mf -C classes .
I created a jar file, sampleproject.jar in DVD directory.

Under DVD directory, I type the javaw -jar sampleproject.jar alone
I got the above error message.

Please advise me.
 
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you show the contents of your manifest.mf?

If you have a look into the jar file, is the manifest.mf included?
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't have the book on hand now.
In the Manifest.mf file, I typed the two lines as told by Monkhouse book. I include sampleproject.gui.ApplicationRunner.
There are just two lines.

I created the sampleproject.jar file. I use jar xf sampleproject.jar to open the file. I only see Meta-Inf folder. Inside it, the Manifest.mf file is the standard one , not the one I created. And I don't see any other folders.
I suggest something wrong with the jar.
 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to make sure the manifest.mf in the meta-inf directory is the one you created. Otherwise java does not know which class contains the main-method.

If you simply copy some command from Andrew's book, it might not have the desired effect because Andrew's setup of his computer will differ from your's. And location from where he invoked scripts/commands may also be different from your's. Always think about this when just copying something from the book.

Here you'll find a bit more info about generating a jar file with a manifest-file.
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are the steps I did:
1. Create a Manifest.mf file. In the file I have two lines:
Manifest-Version : 1.0
Main-Class sampleproject.gui.ApplicationRunner
This Manifest file is in c:\users\workspace\DVD directory

2. Under my c:\users\workspace\DVD (where src anc classes folders are), I type jar -cfm sampleproject.jar Manifest.mf -C classes .

3. Under c:\users\workspace\DVD, I type jar xf sampleproject.jar

4. Meta-Inf folder is created, and there is only one file which is Manifest.mf. No other files are there. (Something wrong here, which I don't know why)

5. In this Manifest.mf file, this file is the default one:
Manifest-Version: 1.0
Manifest-Version: 1.0
Created By: 1.6.0 (Sun Microsystem, Inc)

I am sure step 2, the jar command suggested by Monkhouse is correct. But things don't work out for my machine.
 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I followed exactly the same steps as described in Andrew's book and it worked for me. I even called my manifest file "abc.txt", so my command to jar was:

jar -cfm sampleproject.jar abc.txt -C classes .
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my file structure:
c:\users\workspace\DVD\src for source code
c:\users\workspace\DVD\classes for class files where classes\sampleproject contains the db, remote, gui... packages.
I created sampleproject.jar under c:\users\workspace\DVD directory.
The Manifest.mf that I created is also in c:\users\workspace\DVD directory.

I download the source code, create a project called DVD in Eclipse. There is a bin in Eclipse to store all the compiled files. But I follow Monkhouse's steps in Chapter 9. I create a classes folder under DVD directory.
I checked all the spelling and the spellings are correct.

I guess my jar executable is not working? Or I should try this jar -cfm sampleproject.jar abc.txt classes/sampleproject ?
 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Helen Ma wrote:I guess my jar executable is not working?


That would be weird. But it's easy to test:

1/ Unzip the attached file
2/ Compile the single class in src directory
3/ Then run jar -cfm sampleproject.jar abc.txt -C classes . (from directory containing "abc.txt" and folders "src" + "classes") and it should make a runnable jar without any problem (using "abc.txt" as Manifest.mf file)

Good luck!
Filename: dennysDVDs2.0.zip
File size: 1 Kbytes
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I will try to do that at home.

By the way, I am trying a simple experiment in my office computer using netbean platform
I have c:\myProgram\javaApplication\src. I have a simple program called JavaApplication.java
I compile it under my command prompt. So, I have c:\myProgram\javaApplication\classes\JavaApplication.class
Under c:\myProgram\javaApplication, I type jar -cfm sample.jar abc.txt -C classes .
where abc.txt contains "Main-Class: javaApplication.JavaApplication"

So, I typed jar -xf sample.jar sample.jar
In c:\myProgram\javaApplication, I hava javaApplication package and META-INF folder. I opened the META-INF folder, I
see the default manifest.mf, instead of abc.txt

Here is the problem. jar -cfm does not seem to add acb.txt to META-INF folder.
So, when I type javaw -jar sample.jar , I got the same error message.
 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Helen Ma wrote:where abc.txt contains "Main-Class: javaApplication.JavaApplication"


That's a non-existing class, because based on your directory structure your class is in the default package (instead of the package "javaApplication"
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the confusion. I forget to type the javaapplication as the package. I forgot the mention that in the src there is javaApplication\JavaApplication.java.
So, in DVD directory, there is a classes\javaApplication\JavaApplication.class
 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's very strange. I did exactly the same and there was no problem at all.
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been trying this with my office computer. I got this fail to load Main-Class manifest attribute from xxx.jar.
In the exam, I think it is required to create Manifest.mf file ourselves. If that won't work on either my machine or office machine, it may not run on the assessor's machine.
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like the contents of the abc.txt cannot be added to the meta-inf/manifest.mf file in the jar.
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After I type the jar cfm sample.jar abc.txt -C classes .
I typed jar -xf sample.jar. A meta-inf folder is generated. I open it and see Manifest.mf is there. I opened Manifest.mf , the Main-Class: .... in abc.txt does not exist.
I have a feeling that jar fails to add this Main-Class to the manifest file.
 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you create a runnable jar through an IDE like Eclipse?

Have a look at the ant-script I made (it's in ScjdFaq) and try to use ant to build the runnable jar.
 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Roel.
Thanks for your help.
I found out that the parser that parsed the manifest.mf file is very picky.
In the abc.txt file, after the Main-Class: sampleproject.gui.ApplicationRunner, I need to hit an Enter key to move the cursor to the beginning of the next line. And after Main-Class:, I need to put exactly one space, no more or no less, before sampleproject.

Then, I saved the file and everything works.
 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that picky thingy about Enter key is mentioned in the book (or somewhere else), because I remember having read about it yesterday (but don't know anymore where )

Glad to hear you were able to solve it!
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:I believe that picky thingy about Enter key is mentioned in the book (or somewhere else),



It's mentioned in the Java Manifest doc too
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic