[HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
wdphipps
Posts: 21
Joined: Mon Sep 23, 2019 4:55 pm
Contact:

[HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post 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.

Online
admin
Site Admin
Posts: 10061
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post 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.
If you like our products and services, please help us by posting your review here.

wdphipps
Posts: 21
Joined: Mon Sep 23, 2019 4:55 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post 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

Online
admin
Site Admin
Posts: 10061
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post by admin »

Why does it say Created-By: 1.7.0_09-b05?
Are you using java 7!
If you like our products and services, please help us by posting your review here.

wdphipps
Posts: 21
Joined: Mon Sep 23, 2019 4:55 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post 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.

Online
admin
Site Admin
Posts: 10061
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post by admin »

Good point. Thanks for posting the resolution. It should be updated in the book also.
If you like our products and services, please help us by posting your review here.

wdphipps
Posts: 21
Joined: Mon Sep 23, 2019 4:55 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post 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?

Online
admin
Site Admin
Posts: 10061
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post 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.
If you like our products and services, please help us by posting your review here.


wdphipps
Posts: 21
Joined: Mon Sep 23, 2019 4:55 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post 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.

Online
admin
Site Admin
Posts: 10061
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post by admin »

Looks like you shared it on google drive. requires permission to download.
If you like our products and services, please help us by posting your review here.

wdphipps
Posts: 21
Joined: Mon Sep 23, 2019 4:55 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post by wdphipps »

Granted - gmail doesn't allow me to send jars as-is for some reason

Online
admin
Site Admin
Posts: 10061
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post 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).
If you like our products and services, please help us by posting your review here.

Online
admin
Site Admin
Posts: 10061
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post by admin »

Not related, but you shouldn't have the java files and mymanifest.txt in the jar file.
If you like our products and services, please help us by posting your review here.

wdphipps
Posts: 21
Joined: Mon Sep 23, 2019 4:55 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post 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?

Online
admin
Site Admin
Posts: 10061
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 0, Sec. 1.8.3 - packaging-classes-into-jar] - no main manifest attribute

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: admin and 118 guests