Page 1 of 1
[HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Tue Sep 24, 2019 6:22 pm
by wdphipps
Hi, hoping someone can provide some clarity, as I feel silly asking a basic question.
I'm getting an error "no main manifest attribute, in accounting.jar" when I'm trying out the command java -jar accounting.jar. Here were the steps I took, following the Study Guide:
create a mymanifest.txt file with the manifest information:
Manifest-Version: 1.0
Created-By: 1.7.0_09-b05 (Oracle Corporation)
Main-Class: accounting.Account
-cvfm accounting.jar mymanifest.txt accounting (no issues, it printed added manifest, adding:...etc.)
java -jar accounting.jar (this is where I get the error)
I'd really appreciate any help offered! Thanks in advance.
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Tue Sep 24, 2019 8:44 pm
by admin
1. Check if you have only one jar and you are running that jar.
2. Extract the contents of that jar and very that it has apprpriate manifest.mf file and the required entry in that file.
3. If you still have the problem, I can try logging in remotely to your mc using teamviewer. let me know by sending an email to support@enthuware
Paul.
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Wed Sep 25, 2019 1:25 pm
by wdphipps
Thanks for this tip,
I was able to examine the jar, and in the manifest, no 'main-class:' is there, even though I have it defined in the text file mymanifest.txt. Could there be something wrong with the txt file?
MANIFEST.MF:
Manifest-Version: 1.0
Created-By: 1.7.0_09-b05 (Oracle Corporation)
mymanifest.txt:
Manifest-Version: 1.0
Created-By: 1.7.0_09-b05 (Oracle Corporation)
Main-Class: accounting.Account
-Wendell
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Wed Sep 25, 2019 6:05 pm
by admin
Why does it say Created-By: 1.7.0_09-b05?
Are you using java 7!
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Wed Sep 25, 2019 7:01 pm
by wdphipps
Thanks for your help!
I had simply copied the text from the book, which may have been written during the time of Java 7 (?)
I have also figured out the solution.
I've just learned that with manifest files, a blank line is necessary at the end of the file. I did not have that before, but now it works. Thanks again! I'm sure I'll have more questions in the future, but I appreciate the time now as well.
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Wed Sep 25, 2019 10:20 pm
by admin
Good point. Thanks for posting the resolution. It should be updated in the book also.
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Thu Sep 26, 2019 10:13 pm
by wdphipps
Hoping you can provide one more piece of guidance.
I'm now moving into creating jar files with a custom manifest, but am getting that pesky ClassNotFoundException that I've seen so much in Google searching. I can't seem to get past it.
When I compile and run the code outside of the jar, it works fine. But when I create the jar and then try to execute the jar file, it throws the exception. I'm suspecting it's something in my manifest Main-Class attribue. Here's my manifest:
Manifest-Version: 1.0
Created-By: wdphipps (Some Corperation)
Main-Class: com.enthuware.packTwo.ClassTwo
(blank line here)
Any idea what the issue is?
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Thu Sep 26, 2019 11:20 pm
by admin
Generally, the only issue that usually causes CNF is that your class file is not stored in the right path within the jar. Email me your jar and I can take a look.
If you are online right now, I can login to your m/c remotely using teamviewer and see what's going on.
Paul.
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Fri Sep 27, 2019 2:07 am
by wdphipps
Email is on the way!
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Fri Sep 27, 2019 2:08 am
by wdphipps
admin wrote: ↑Thu Sep 26, 2019 11:20 pm
Generally, the only issue that usually causes CNF is that your class file is not stored in the right path within the jar. Email me your jar and I can take a look.
If you are online right now, I can login to your m/c remotely using teamviewer and see what's going on.
Paul.
I'm available right now if an admin currently is as well.
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Fri Sep 27, 2019 2:11 am
by admin
Looks like you shared it on google drive. requires permission to download.
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Fri Sep 27, 2019 2:12 am
by wdphipps
Granted - gmail doesn't allow me to send jars as-is for some reason
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Fri Sep 27, 2019 2:14 am
by admin
You have a mistake in your main-class entry in manifest file. In the manifest, you have com.enthuware.packTwo.ClassTwo
but the package is com.enthuware.packtwo.ClassTwo (packtwo is in lower case).
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Fri Sep 27, 2019 2:16 am
by admin
Not related, but you shouldn't have the java files and mymanifest.txt in the jar file.
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Fri Sep 27, 2019 2:20 am
by wdphipps
Thanks for that catch. The jar now works.
So it's better practice to only have the class files in the jar file?
In that case, i would only put the package and its contents in the jar file, correct?
Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute
Posted: Fri Sep 27, 2019 3:33 am
by admin
wdphipps wrote: ↑Fri Sep 27, 2019 2:20 am
Thanks for that catch. The jar now works.
So it's better practice to only have the class files in the jar file?
Yes.
In that case, i would only put the package and its contents in the jar file, correct?
Yes.