• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Executable jar Failed to load Main-Class manifest attribute

 
Ranch Hand
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 80097
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nevermind it's not fixed... it wont let me change MANIFEST.MF
 
Jo Young
Ranch Hand
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 80097
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 80097
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... 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
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... 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
Marshal
Posts: 80097
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 80097
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 34
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Get me the mayor's office! I need to tell him about this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic