Failed to load Manifest attribute - eclipse - java

I am trying to export jar of a project via eclipse
when I run that jar it gives error "failed to load Manifest attribute"
although I give main-class-name in manifest file but it is not working
I put following in Manifest class
Manifest-Version: 1.0
Main-Class: HangMan
For additional information: directory structure of Main class is
"/TestHangMan/src/test/HangMan.java"
what I am doing wrong?
EDIT: I forgot to mention, It(HangMan) is an Applet.Apologies!

Try exporting the Project as "Runnable Jar" instead of "Jar". It will configure your Manifest for you just fine. Im not 100% sure, where that Error comes from, but I think it is because it is missing the classpath for your jar.

There is a simple way to export simple Java programs as runnable JARs from Eclipse:
Remove the MANIFEST.MF
Move HangMan.java to the src folder (that's where your final code should be located)
Run your program once inside of Eclipse to create a launch configuration.
Choose File->Export->Java->Runnable JAR File
In the dialog Runnable JAR file Export choose the correct launch configuration and destination. If you are not using any 3rd party libraries leave the rest as a default.
Try running the JAR, on Linux for example with
java -jar $HOME/tmp/HangMan.jar
Good luck!
Update:
OP's HangMan is a Java applet (see comments) :-).

Related

jar file works in eclipse folder but not out of it.Main class notfound

My groovy (ant1.8.1 for build)project was build in jdk1.5 and now i am making some changes and upgrading to jdk1.8 .
When i build and make jar ,it works fine from the folder where code is in eclipse.
but when copy that jar and try to run get below-
Error :could not find or load main class Run.
Rest all jars are as below(same as used in jdk5)
groovy-all-1.6.9.jar
commons-codec-1.4.jar
commons-httpclient-3.0-rc4.jar
commons-logging-1.1.1.jar
commons-net-2.0.jar
lib/log4j-1.2.15.jar
jtds-1.2.5.jar
httpmime-4.0.1.jar
When you say "run", I understand you mean something like:
java -jar MyJar.jar
You should check your MANIFEST file inside the JAR and make sure your Main-Class is defined as you need.
Main-Class: pakage.name.ClassName.class
And the corresponding pakage.name.ClassName.class exists in your jar file (or is included in any of the libraries accessible through classpath)
Check this anyway Setting application entry point

Program runs within eclipse IDE but will not run as a jar file

My program runs fine within the eclipse ide. When I try to run it as a jar file I get the following message:
exception in thread "main" java.lang.noClassFoundError:
org/apache/logging/logfactory at
org.apache.http.conn.ssl.defaultHostNameVerifier.(BotTest.java:65) at BotTest.main(BotTest.java:100)
Caused by:Java.lang.ClassNotFoundException
I do have 4 libraries in the project and I use the option
"Extract required libraries into generated jar".
Instead of using extract required libraries into generated jar, select "package required library into generated JAR" option. It will work.
As per my comment, you may not be properly setting up the manifest file to recognize your library jar files. The manifest file should have a line that looks something like:
Class-Path: some.jar other.jar third.jar
Please also check out the many similar questions on this site.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpEntity

This error keeps bothering me for a long while. I need to export my java app to .jar and when I run it (java -jar test.jar) I get this error message. I've checked that the apache-core-4.3.3.jar is included, I've checked that it contains HttpEntity class, I've checked java build path and manifest but everything is OK.
The weirdest thing is that in my code I don't try to import org.apache.http.HttpEntity at all. And I've got only 3 classes so I wouldn't miss it.
Manifest file:
Manifest-Version: 1.0
Main-Class: Main
Classes:
EDIT
I export it like this, so I think imported jars' content is exported to my test.jar file thanks to Export Java source files and resources, am I right?
What is the next thing I should do?
You are exporting it as a 'JAR file', try using the 'runnable JAR file' wizzard.
Right click your eclipse project -> Export.. -> Runnable JAR file -> Pick your configuration and choose "package required libraries into generated JAR". This will make eclipse do al the work for you.
You have to add the jars to the classpath in commandline:
java -cp <list of jars> -jar test.jar
Update the class path. It should work

How to package required external libraries AND sources in Eclipse

I have an issue that is really annoying right now.
For a school project (that is due on monday :( ), I have to submit a .JAR file that is a stand alone app and that includes sources.
However, in Eclipse, I didn't find how to export the sources and at the same time, include the required libraries.
My BuildPath is set up this way :
http://image.noelshack.com/fichiers/2014/19/1399746312-owp08.png
When I do :
Export as a runnable JAR file, everything works in my program but I don't have the sources inside the JAR
Export as a JAR File, I can add my sources, but when i try to run the JAR file, I have this exception :
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Here are my settings :
http://image.noelshack.com/fichiers/2014/19/1399746469-sans-titre.png
I really don't know what to do, I've been searching for hours now, can someone help me ?
Thank you in advance.
Regards,
Azsde.
Well, the short answer is that eclipse doesn't support doing that directly. This is why most people use other tools such as Ant or Maven in their projects, rather than relying on the IDE.
You can work around eclipse's lack of an export source option in the runnable jar export wizard in one of two ways:
You can create a runnable jar and then manually add your source files to it
You can create a normal jar which includes your source files and add a MANIFEST.MF file to it.
Adding source files manually
This is what I would normally consider a terrible option, but since this is a homework assignment, there are two mitigating factors:
this is a one-off
you are short on time
If you have neither the time nor inclination to learn the details about manifests, I would recommend this option.
Adding your own MANIFEST.MF
As you may have noticed, even when you select the option to have eclipse generate your manifest in the export wizard, your jar file won't actually run. If you open up the 'normal' jar file and look at the generated manifest file it will look something like this (for a simple HelloWorld program using one third party library):
Manifest-Version: 1.0
Main-Class: HelloWorld
Whereas if you open up the manifest file for an exported runnable jar it will look something more like this (for the same program):
Manifest-Version: 1.0
Rsrc-Class-Path: ./ commons-lang3-3.3.1.jar
Class-Path: .
Rsrc-Main-Class: HelloWorld
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
As you can see, the generated manifest file is failing to include support for third party libraries.
What you would need to do in this case is write your own manifest file and keep it as a resource in your project. Then do a normal jar export, and on the last page of the wizard select the Use existing manifest from workspace option, and point it at your own manifest file.
This will have the advantage that you can export a new runnable jar whenever you like, including your source files, and without requiring manual tinkering each time.
If you're interested in working with manifest files, there's a good tutorial on oracle's website here that can help you get started:
http://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html

"Could not find main method from given launch configuration" error when exporting jar from Eclipse

I developed my program using Eclipse as my IDE. I used to use File|Export| Runnable JAR file option for creating dist build for client.
I was working with project using Run or (often) Debug button in eclipse (so I have configuration for project with valid main method).
Unfortunately when I created build yesterday I had following error when I tried to run app:
Failed to load Main-Class manifest attribute from My.jar
Then when I retried exporting I found the following problem in export log:
Could not find main method from given launch configuration
I have no idea what could cause this problem. I think I hadn't change anything in my project configuration. And I'm test my builds so I'm sure this option used to work correctly.
I will appreciate any help.
Are you selecting correct 'Launch Configuration' in the export dialog? Make sure it's from your project.
Also, once exported you could unzip jar file and look into 'META-INF/MANIFEST.MF' file - there should be 'Main-Class' entry with fully qualified name of your class where the main() method is.
I had this problem and none of the other options worked. Even removing and starting with a new workspace. In my case the problem was that I hadn't manually added the "classes" directory of my project to the classpath of the debug configuration that I was using to debug the java app. I don't know why it didn't pick up the classes directory automatically as part of the project from which I was running the app. In any case it started working again after that.
just had the same problem :s
it's annoying but easy to manually fix in the manifest file.
open the .jar file with winrar or 7zip.
locate the manifest file (META-INF folder)
change it to this.
Manifest-Version: 1.0
main-class: (package).(main-class)
In my case i had it in the default package.
Manifest-Version: 1.0
main-class: run
If you are not able to find your class file in Launch configuration, Right click on your project - > run as Java Application. Now export again.

Categories