aspose file tools*
The moose likes Java in General and the fly likes Executable jar Failed to load Main-Class manifest attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Executable jar Failed to load Main-Class manifest attribute" Watch "Executable jar Failed to load Main-Class manifest attribute" New topic
Author

Executable jar Failed to load Main-Class manifest attribute

Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

I wrote a fairly simple program the purpose of which is to remind me to do my pushups every 30 minutes because I keep getting too into what I am doing and losing track of time, but I dont want to bog down my system by having it constantly running in the back through JDeveloper and I just generally want it more easily accessible than to have to open up JDeveloper every day in order to run it (I pretty much have it open every day anyway... but I would just really rather have a real/practical usable version of the program instead of having to run it in testing form... maybe if at some point i want to pass it around or something)... anyway... I have been doing rather extensive research on how to create the executable jar and I made the manifest page and put the Main-Class: Timer.myTimer and everything but I am still getting the error "Failed to load Main-Class manifest attribute from <File-Path>" I have tried doing it in cmd like I saw in most places I looked and I cant even get it to do anything I get an error saying that jar is not a valid command or something like that, I have tried writing the manifest with and without the package name (there is only one class in the entire jar) I have tried writing it as Manifest-Classname: like I saw in one thread somewhere... I dont know what else to try... help would be greatly appreciated
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Phew - that is very hard to read.

List the content of your jar file using

jar -tf your-jar.jar

Then extract the manifest using

jar -xf your-jar.jar META-INF/MANIFEST.MF

Post the jar listing and the content of MANIFEST.MF.

Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
Welcome to the Ranch

Do you really get an error saying jar is not recognised? Does it look anything like the errors in this tutorial?
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

James Sabre wrote:Phew - that is very hard to read.

List the content of your jar file using

jar -tf your-jar.jar

Then extract the manifest using

jar -xf your-jar.jar META-INF/MANIFEST.MF

Post the jar listing and the content of MANIFEST.MF.


I am not using cmd I am using JDeveloper.

I tried using cmd to do this and I got this:

'jar' is not recognized as an internal or external command,
operable program or batch file.

and I tried looking around to try to find a jar.exe file or something that I could point to and call the command that way and it doesnt exist anywhere on my computer. I found a whole range of java.exe (java.exe, javax.exe, etc) in the JRE directory and in the C:\Windows\System32 directory just as expected but no jar.exe

however JDev is so kind as to give me a jar listing after it deploys the jar... it says

META-INF/MANAFEST.MF
myTimer.class
timer/myTimer.class

........ wait a second... why does it have manifest.mf instead of the manifest that I wrote myTimer.mf? hmm... my problem may be solved lol at least the problem of the class not working... still cant use the jar command.
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

nevermind it's not fixed... it wont let me change MANIFEST.MF
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

Campbell Ritchie wrote:Welcome to the Ranch



thank you hopefully joining this ranch will help me be able to get my work done (and maybe provide a little help in play as well) and I can also hopefully one day lend some of my limited wisdom elsewhere
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Jo Young wrote:
I am not using cmd I am using JDeveloper.


I haven't used it for some time but I know that JDeveloper allows you to specify that it should create a jar file and specify the main class.

I tried using cmd to do this and I got this:

'jar' is not recognized as an internal or external command,
operable program or batch file.


Which means you have not got the bin directory of your JDK as one element of the PATH environment variable.


and I tried looking around to try to find a jar.exe file or something that I could point to and call the command that way and it doesnt exist anywhere on my computer. I found a whole range of java.exe (java.exe, javax.exe, etc) in the JRE directory and in the C:\Windows\System32 directory just as expected but no jar.exe

however JDev is so kind as to give me a jar listing after it deploys the jar... it says

META-INF/MANAFEST.MF
myTimer.class
timer/myTimer.class

........ wait a second... why does it have manifest.mf instead of the manifest that I wrote myTimer.mf? hmm... my problem may be solved lol at least the problem of the class not working... still cant use the jar command.


I could be wrong but I don't think that in JDeveloper you have to explicitly create the manifest.
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

James Sabre wrote:
Jo Young wrote:
and I tried looking around to try to find a jar.exe file or something that I could point to and call the command that way and it doesnt exist anywhere on my computer. I found a whole range of java.exe (java.exe, javax.exe, etc) in the JRE directory and in the C:\Windows\System32 directory just as expected but no jar.exe

however JDev is so kind as to give me a jar listing after it deploys the jar... it says

META-INF/MANAFEST.MF
myTimer.class
timer/myTimer.class

........ wait a second... why does it have manifest.mf instead of the manifest that I wrote myTimer.mf? hmm... my problem may be solved lol at least the problem of the class not working... still cant use the jar command.


I could be wrong but I don't think that in JDeveloper you have to explicitly create the manifest.


ok I figured out how to set the main class in the manifest using JDev... but I tried to browse and find my class and it was giving classes from typical java libraries it didnt offer the class that I made
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

woohoo I got the manifest made!! and umm... wtf?? I ran it and got a new error that says basically the exact same thing... could not find the main class timer.myTimer. Program will exit.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

If you double click the JAR file you must ignore that error. The javaw.exe tool has poor error handling - no matter what exception or error the main class throws, this is the message you're going to get. You'll need to debug by opening a command line and running the program using "java -jar your-jar.jar". That way you'll get to see the actual exception / error that is thrown.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
I presume you are running things all right from the command line? If you haven't got the "not recognized" error sorted out yet, there is a description of it in the Java™ Tutorials. Look for "common errors". Open your Java™ installation folder, and check that the jar.exe (or "jar") file is inside its "bin" directory. Check your PATH, and the link given in the "common errors" file. That link (§4) tells you more about the PATH, and how to set it. That usually solves the "not recognized" problem.
If that doesn't help, ask again.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
If you haven't got the "jar" or "jar.exe" files in your installation folder, you might have to reinstall Java™. Remember they need to be in "bin". Try this sort of thing at the command line:
javac -version
javac 1.6.0_22
C:\\Program Files\java\jdk1.6.0_22\bin\jar -version
Use the same number as the version number you got from -version. You might need quotes "" around that lst instruction if it contains spaces.
See whether you get a version number or "not recognized".
Remember when you set a PATH entry on Windows®, it starts with the drive letter (commonly C) and ends with "bin".
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

Rob... I ran what you said and got the same "Could not find the main class: timer.myTimer. Program will exit"

Campbell... I dont have a JDK at all in my program files... wait... AH HA!!! somehow my search for "jar.exe" in the root C: drive didnt find the oracle/middleware/jdk160_18/bin that is in the C: drive which I very clearly see a jar.exe file right in front of my face... thank you I will try recreating my jar without using JDev and hopefully with less fail.
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

... ok I got the jar created by way of cmd finally... but now I tried to run it and got "Failed to load Main-Class manifest attribute from <filepath>" I created my jar using the myTimer class and i wrote a myTimer.mf file that has the Manifest-Version: 1.0 and the Main-Class: Timer.myTimer in it... does the manifest have to be named manifest.txt originally? the first thing I read about how to do this had the manifest as <the same name as the class>.mf is that wrong?
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

So why don't you no do as I suggested in my first reply. i.e. List the jar content index and the content of the manifest. Given these almost anybody here will be able to say exactly what is wrong.

Make your you list the content of the manifest file that is in your jar file.
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

I am not familiar with JDeveloper, I use a really simple IDE called JGrasp, that has built in support for creating .jar files. You could give that a try if you like, thats me ~30 secs to make a .jar file.
http://www.jgrasp.org/


Hunter

"If the facts don't fit the theory, get new facts" --Albert Einstein
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Hunter McMillen wrote:I am not familiar with JDeveloper, I use a really simple IDE called JGrasp, that has built in support for creating .jar files. You could give that a try if you like, thats me ~30 secs to make a .jar file.
http://www.jgrasp.org/


Hunter


Every Java development IDE I have worked with has the ability to create executable jar files. JDeveloper certainly does. The problem is not the IDE and I don't think that pushing the OP towards a different IDE is going to help him at all. If anything i would suggest that he OP throw away his IDE and use a text editor and the command line. That way he would understand what JDeveloper is doing behind the scenes to make it easy for him.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Jo Young wrote:"Could not find the main class: timer.myTimer. Program will exit"

Jo Young wrote:Main-Class: Timer.myTimer

You are aware that Java is case sensitive, aren't you? timer.myTimer is not the same as Timer.myTimer.

Also, does your manifest file end with a line break? Because practice has shown that without an ending line break the manifest won't be read properly in some cases.
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

James Sabre wrote:So why don't you no do as I suggested in my first reply. i.e. List the jar content index and the content of the manifest. Given these almost anybody here will be able to say exactly what is wrong.

Make your you list the content of the manifest file that is in your jar file.


ok for some reason it isnt loading my manifest into the jar...

C:\JarFile>C:\oracle\Middleware1013\jdk160_18\bin\jar -tf myTimer.jar
META-INF/
META-INF/MANIFEST.MF
myTimer.class

C:\JarFile>C:\oracle\Middleware1013\jdk160_18\bin\jar -xf myTimer.jar META-INF/MANIFEST.MF
<nothing>

I tried it with Manifest.txt Manifest.mf and myTimer.mf all of which contain:

Manifest-Version: 1.0
Main-Class: Timer.myTimer

every time, nothing in the manifest.

James Sabre wrote: Every Java development IDE I have worked with has the ability to create executable jar files. JDeveloper certainly does. The problem is not the IDE and I don't think that pushing the OP towards a different IDE is going to help him at all. If anything i would suggest that he OP throw away his IDE and use a text editor and the command line. That way he would understand what JDeveloper is doing behind the scenes to make it easy for him.


you sound like my supervisor lol

but no seriously I agree the only reason why I was trying to use JDeveloper to make the jar earlier was because I had already tried it with cmd and it blew up on me... unfortunately it blew up on me in JDev too so that didnt really help me at all... but now that I finally figured out where my jar.exe is and my cmd is actually working I have been using cmd
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

Rob Spoor wrote:
Jo Young wrote:"Could not find the main class: timer.myTimer. Program will exit"

Jo Young wrote:Main-Class: Timer.myTimer

You are aware that Java is case sensitive, aren't you? timer.myTimer is not the same as Timer.myTimer.

Also, does your manifest file end with a line break? Because practice has shown that without an ending line break the manifest won't be read properly in some cases.


yes I am aware of that and I caught that and fixed that in my current manifest file... hmm... no I dont think it does have a line break... thank you I will try that... if it is really that simple I think I might cry lol
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

... nope... not that simple... it is at least reading my manifest now... but I am back to the "Could not find the main class: Timer.myTimer. Program will exit" (and yes this time I have the case correct)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
If your most recent JDK is 1.6.0_18, you might do well to download and reinstall it. You will doubtless remember you can find it here. You should find a link to the installation instructions in that "common problems" page I told you about earlier. It is quite easy except §4 about setting the PATH.

I would have thought your IDE would have added the new line to the mainfest file automatically.
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

ooooo I got it!!! I was making it too complicated apparently having only one class in the jar I didnt need to include the package name... I changed Main-Class: to just myTimer and it worked thank you very much to all of you for your help!!!
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Jo Young wrote:[
C:\JarFile>C:\oracle\Middleware1013\jdk160_18\bin\jar -tf myTimer.jar
META-INF/
META-INF/MANIFEST.MF
myTimer.class

C:\JarFile>C:\oracle\Middleware1013\jdk160_18\bin\jar -xf myTimer.jar META-INF/MANIFEST.MF
<nothing>

I tried it with Manifest.txt Manifest.mf and myTimer.mf all of which contain:

Manifest-Version: 1.0
Main-Class: Timer.myTimer


Your manifest says your class "myTimer" is in package "Timer" BUT BUT BUT the jar content shown above indicates that that myTimer.class in not in package "Timer".

every time, nothing in the manifest.


You don't need to create an explicit manifest. JDeveloper allows you to specify a deployment profile in which you just select the class to use as the main class. It then automatically creates a jar file with an appropriate manifest.

You need to spend some time learning about how JDeveloper works.
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

Campbell Ritchie wrote:If your most recent JDK is 1.6.0_18, you might do well to download and reinstall it. You will doubtless remember you can find it here. You should find a link to the installation instructions in that "common problems" page I told you about earlier. It is quite easy except §4 about setting the PATH.

I would have thought your IDE would have added the new line to the mainfest file automatically.


is that not a very recent JDK? that JDK came with my Oracle Middleware 11g Development software and those are version 11.4 which as far as I know are the latest version of Middleware... I just finally got all my software downloaded back onto my computer last week.
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

James Sabre wrote:

You don't need to create an explicit manifest. JDeveloper allows you to specify a deployment profile in which you just select the class to use as the main class. It then automatically creates a jar file with an appropriate manifest.

You need to spend some time learning about how JDeveloper works.


I didn't do that in JDeveloper James I got my cmd working and started working in cmd to create the jar file. And I am aware that JDeveloper allows you to specify the deployment profile. I am the type of person that cant learn and grasp how something works unless I'm actually working with it and doing it and I have only been programming in Java for a few months... I have only been at this job at all for a little over a year and most of that time we didn't have any work for me to do and I had to use that time doing my upgrade training to get my 5-level so that I was even considered competent to start really getting into coding (I am in the Air Force)
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

now I just gotta make a way to end the program without deleting it lol

when I originally made it I made it to be running in the background from JDev so all I had to do to end it was press the big red square... now that its out of development it is just running in the background with no way to stop it lol I think I can do this one myself though I just gotta go in and make a Java Swing Clock thank all of you again for your help
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
You're welcome

The 1.6.0_18 update is getting on for a year old; update no 25 came out a few weeks ago.

I appear to be a little out there.

Apparently there is now a no 26. I looked up this Wikipedia page where it says update 18 came out in January last year.
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

Campbell Ritchie wrote:You're welcome

The 1.6.0_18 update is getting on for a year old; update no 25 came out a few weeks ago.

I appear to be a little out there.

Apparently there is now a no 26. I looked up this Wikipedia page where it says update 18 came out in January last year.


wow then either my office is way behind on Oracle updates (which is certainly possible I guess) or Oracle is way behind on their use of JDK (which also could probably be very possible)
Jo Young
Ranch Hand

Joined: Jun 08, 2011
Posts: 34

I'm back... I made a second class that has Swing on it and creates a window... and now it is having the problem of not being able to find the main class that is in the manifest again... and I have tried everything that I was directed to do that finally got the other one fixed as well as all the different things that didnt work last time and it keeps giving me the same error...

currently I have...

C:\JarFile>C:\Oracle\Middleware1013\jdk160_18\bin\jar -tf PushupTimer.jar
META-INF/
META-INF/MANIFEST.MF
myTimer.class
timeClock.class

C:\JarFile>C:\Oracle\Middleware1013\jdk160_18\bin\jar -xf PushupTimer.jar META-INF/MANIFEST.MF

Manifest-Version: 1.0
Created-By: 1.6.0_18 (Sun Microsystems Inc.)
Main-Class: myTimer

any ideas?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Executable jar Failed to load Main-Class manifest attribute