I've just made a game in netbeans. The Problem is that after builting the game. I'm not able to execute the jar file and getting the exception:
Failed to load Main-Class manifest attribute from
Game.jar
What to do???
For a JAR to be self-executable, you have to include the Main-Class line in a manifest.
I'm not a NetBeans user, but this is how it's done.
Create a manifest.mf file:
Main-Class: YourGame
<newline>
Build the jar:
jar cmf manifest.mf Game.jar path/to/classes/*.class
You should now be able to to double-click on the JAR to run it (assuming Windows), or you can run it via the command line:
java -jar Game.jar
Of course, you can always run from the command line without the need for a manifest:
java -cp .;Game.jar YourGame
The Main-Class attribute needs a new line after it in order to be parsed correctly.
Show your manifest.mf,
Edit manifest file as proposed by others, or in NetBeans just right-click the project (in sidebar), select Properties, category Run and hit Browse... next to Main Class.
Related
I just made my first Java program and it worked perfectly, when I launched it by 'IDEA'. Then I wanted to create an executable file to launch it separately. 'IDEA' helped me create a jar file with this content inside it:
Some classes (*.class files).
Folder META-INF with MANIFEST.MF in it. MANIFEST.MF has only 2
lines: version info and "Main-Class: ru.nikolski.2048.main".
When I double click on the jar file, nothing happens. When I launch the jar file by 'IDEA', it writes the following:
"C:\Program Files\Java\jdk1.7.0_51\bin\java" -Dfile.encoding=windows-1251 -jar C:\Users\Osn\IdeaProjects\Game2048\out\artifacts\Game2048_jar\Game2048.jar
Error: Could not find or load main class ru.nikolski.2048.main
I tried to make folder ru/nikolski/2048 inside the jar file, and put all *.class files in it, but it didnt help, I got the same error.
What am I doing wrong?
I solved the problem just correcting the line in MANIFEST.MF:
Main-Class: Main
as my class with main method has the name 'Main'.
I have some dependencies that I need to specify in the manifest. So I created a manifest file manually and when doing that I exported my selected files and do next >> next and then choose "use existing manifest from file". this is the manifest I have locally:
Manifest-Version: 1.0
Main-Class: com.placeholder.ProcessServer
Class-Path: . ProcessServer_lib/commons-net-3.3.jar ProcessServer_lib/
com.ibm.mq.headers.jar ProcessServer_lib/db2jcc.jar ProcessServer_lib
/db2jcc_license_cu.jar ProcessServer_lib/db2jcc_license_cisuz.jar Pro
cessServer_lib/com.ibm.mq.jar ProcessServer_lib/com.ibm.mq.commonserv
ices.jar ProcessServer_lib/connector.jar ProcessServer_lib/com.ibm.mq
.jmqi.jar ProcessServer_lib/log4j-1.2.17.jar
I placed the jar in my unix box and invoke it via a shell script using -jar however it gives me a classdef not found exception. Upon seeing the jar generated via decomplier/zip utility I can see the manifest only contains the main-Class line not the class-path.
While exporting the jar should I unselect the buildpath that comes in the right hand box selection ?
I'm doing these deployment works for the first time, but I have tried for 1 day using -cp to specify jar folder and main class but I still haven't found a way. Could somebody help me or give me advice?
p.s. I don't use maven/ant so no need to advice me on that.
There's a bug in Eclipse where it won't export the last line of your manifest if you don't leave a trailing newline.
Export your project using the export to runnable jar of Eclipse and remeber to choose between these :
Extract required libraries into generated JAR : to inflate the referenced jar files and copy the classes into the generated jar
Package required libraries into generated JAR : to copy the referenced jar files as is into the generated jar
Copy required libraries into a sub-folder next to the generated JAR
See here
I am trying to run jar file through
java -jar jts.jar
but it is unable to run because it's Manifest.mf do not contain 'Main-Class' attribute, which is necessary for a jar file to run.
I am have same problem with 9-10 .jar files.
Help me with how to find those mainclass in jar files, there is no any directly defined mainclass in jar file.
How should I find the correct mainclass and how should I add it to manifest.mf
On command line you can use following command to generate jar having existing manifest.
jar cvfm MyJarName.jar manifest.txt *.class
Refer this page for more details.
Alternatively, if you are using eclipse. Please follow steps mentioned here to export jar.
if you have your Main-Class attribute on the last line of your manifest.txt, it vanishes if you do not have a new line at the end. Very annoying, but always make sure you have a new line at the end of your manifest file.
1. You can open the jar file with winzip or winrar.
2. Open manifest file in notepad.
3. Add main-class: ClassNameContianingMainMethod.
4. Save the file and then run it
I recently finished a project which works as it is supposed to in my Eclipse IDE as both multiple files and as a single file.
Eclipse exports the jar file and only makes noise about the warnings.
When I go to run the jar file with a double-click, the cursor seems to flash to a hourglass for less than a second and then nothing. When I try to run the jar file from the command line with java -jar myJarFile.jar the command prompt window seems to wait a second and then brings the file path line and cursor with no errors and no other messages.
I have double checked both my Path variable and that I have the latest version of Java installed.
Any suggestions?
Check this thread: Failing to execute the jar file using java -jar command
Basically, what you need to do is when you run the jar, you need to specify the class to be executed in the command line, like so:
java -cp test.jar com.app.ClassName
Did you just make a jar file, or a runnable jar file? If you only did the former then it will not execute on a double click. So it's Right Click the project in Eclipse -> Export -> Runnable JAR File -> Choose the appropriate Launch Configuration -> Choose where you want it to go.
Confirm that your application code is in the jar file:
jar tf myJarFile.jar
Confirm that your application's main class is listed in the Main-Class attribute in the manifest, and that any other jar files needed by your application are listed in the Class-Path attribute:
jar xf myJarFile.jar META-INF/MANIFEST.MF
cat META-INF/MANIFEST.MF
Try running with verbose logging of classes being loaded; this should show if some necessary class can't be found:
java -verbose:class -jar myJarFile.jar
I have created a JAR file in this way jar cf jar-file input-files. Now, I'm trying to run it. Running it does not work (jre command is not found):
jre -cp app.jar MainClass
This does not work either:
java -jar main.jar
(Failed to load Main-Class manifest attribute from main.jar).
I also found out that
To run an application packaged as a
JAR file (version 1.2 -- requires
Main-Class manifest header)
What is the "Main-Class manifest header"? How do I create it and where do I put it?
I'm not sure I believe your symptoms:
If the jre command isn't found, then running jre -cp app.jar should give the same error
Just adding a JAR file to the classpath shouldn't give the error you're seeing
I'd expect you to see this error if you run:
java -jar app.jar
The Main-Class header needs to be in the manifest for the JAR file - this is metadata about things like other required libraries. See the Sun documentation for how to create an appropriate manifest. Basically you need to create a text file which includes a line like this:
Main-Class: MainClass
Then run
jar cfm app.jar manifest.txt *.class
set the classpath and compile
javac -classpath "C:\Program Files\Java\jdk1.6.0_updateVersion\tools.jar" yourApp.java
create manifest.txt
Main-Class: yourApp newline
create yourApp.jar
jar cvf0m yourApp.jar manifest.txt yourApp.class
run yourApp.jar
java -jar yourApp.jar
You can run with:
java -cp .;app.jar package.MainClass
It works for me if there is no manifest in the JAR file.
I got this error, and it was because I had the arguments in the wrong order:
CORRECT
java maui.main.Examples tagging -jar maui-1.0.jar
WRONG
java -jar maui-1.0.jar maui.main.Examples tagging
The easiest way to be sure that you have created the runnable JAR file correctly, with the appropriate manifest file, is to use Eclipse to build it for you. In your Eclipse project, you basically just select File/Export from the menu, and follow the prompts.
That way, you can be sure that your JAR file is correct and will know to look elsewhere if there is still an issue. The process is described in full in FAQ How do I create an executable JAR file for a stand-alone SWT program?.
I was getting the same error when i ran:
jar cvfm test.jar Test.class Manifest.txt
What resolved it was this:
jar cvfm test.jar Manifest.txt Test.class
My manifest has the entry point as given in oracle docs (make sure there is a new line character at the end of the file):
Main-Class: Test
Try
java -cp .:mail-1.4.1.jar JavaxMailHTML
no need to have manifest file.
I discovered that I was also having this error in NetBeans.
I hope the following is helpful.
Make sure that when you go to Project Configuration you set the main class you intend for running.
Do a Build or Clean Build
Place the jar file where you wish and try: java -jar "YourProject.jar" again at the command line.
This was the problem I was getting because I had other "test" programs I was using in NetBeans and I had to make sure the Main Class under the Run portion of the Project configuration was set correctly.
many blessings,
John P
I faced the same problem. This unix command is not able to find the main class. This is because the runtime and compile time JDK versions are different. Make the jar through eclipse after changing the java compiler version. The following link helped me.
http://crunchify.com/exception-in-thread-main-java-lang-unsupportedclassversionerror-comcrunchifymain-unsupported-major-minor-version-51-0/
Try running the jar created after this step and then execute it
If your class path is fully specified in manifest,
maybe you need the last version of java runtime environment.
My problem fixed when i reinstalled the jre 8.
If you using eclipse, try below:
1. Right click on the project -> select Export
2. Select Runnable Jar file in the select an export destination
3. Enter jar's name and Select "Package required ... " (second radio button) -> Finish
Hope this helps...!