.jar file do not contain Main-Class attribute in manifest.mf - java

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

Related

how to make an executable jar which includes a java and a jar file

I have a java file simpleMail.java and a jar file java-mail-1.4.jar (which is used in simpleMail.java). What I want to do is make an executable jar file out of these files and run on cmd.
Step 1. create manifest.txt file as
Main-Class: Main-Class-Name
Step2. compile all classes.
Step 3. run JDK's jar.exe utility like:
jar cvfm JarName.jar manifest.txt .class
cvfm is create a jar; show verbose output; specify the output jar file name; specify the manifest file name. (.class means all class files in the current directory.)
Step 4. specify jar dependency on classpath.
For detail refer http://www.skylit.com/javamethods/faqs/createjar.html

Creating Executable jar from CMD prompt

I have following class files,jar and manifest in a directory
Dot.class
Bridge.class
jsch.jar
MANIFEST.MD
Manifest file contains following two lines
Manifest-Version: 1.0
Main-Class:Dot
command used for creating jar file
jar cfm dot.jar MANIFEST.MD *
While executing generated jar it throws error saying no main manifest attribute
While seeing inside the generated jar META-INF folder contains auto generated manifest file, it doesn't have content for my main class.
I couldn't find successful steps ,Please correct me.
Had the same issue a few days ago and couldn't resolve it with the manifest file so I put the main class as a build parameter like this:
jar cfe Main.jar MainClass *.class
Add a space after ':' as in
Main-Class: Dot
Add a new line after the last line, in your case after Main-Class entry:
Manifest-Version: 1.0
Main-Class: Dot
The reason for 2. ist documented in https://docs.oracle.com/javase/tutorial/deployment/jar/modman.html in detail.
I tried below command and it works with the jar produced which i post.
java -cp "jsch.jar;." Dot

Jar file when extracted and rebuilt, isn't working

I'll try to be clear and concise on this.
i have a jar file of a project which is working perfectly. Now I need to make some changes to the application so i extracted that jar using this command.
jar xf jwire.jar
the files extracted are
META-INF (containing manifest file)
Resources (containing pictures used in application)
Jwire (containg classes and java files)
.classpath
.project
manifest.mf (another manifest file with some other path to main class)
i also added two empty folders src and bin here on somebodys suggestion.
now i'm trying to create the jar file again using all these folders.
Without making any type of changes I'm trying to rebuild this jar using the following
jar cf newjar.jar G:\Project1\project
NOTE:- I am guessing it's the right way to build the file. Please point if it's not right.
G:\Project1\project is the path to above mentioned files and folders.
The jar created using this is of size 729kb while the earlier one had 711Kb and when I run it using the following command.
java -jar newjwire.jar
I get the following message
no main manifest attribute, in newjwire.jar
Next i tried extracting this newjwire.jar file in order to see its manifest file. I got this folder META-INF containing the MANIFEST.MF file. it didn't have the path to the main class , So I edited it and put the modified file back on using the following command
jar uf newjwire.jar META-INF/MANIFEST.MF
when I run this jar, I get the following message
Error: Ivalid or corrupt jarfile newjwire.jar
What am I doing wrong? Am I building the jar file the right way? I used eclipse juno too and it gave the same message to that mainclass is missing. There is a main class consisting the main function. Is this something has to do with My orignal jar having two MANIFEST file.
I hope the problem is understandable. Clear and detailed answers will be appreciated.
you're supposed to update JAR files by jar uf jar-file input-file(s)
see this link: http://docs.oracle.com/javase/tutorial/deployment/jar/update.html
According to this page you need to EITHER have Manifest.txt present when you create or update the JAR, or use the e option to specify the main class. Probably the latter would make more sense in your case.
jar cfe newjar.jar mypackage.MainClass G:\Project1\project

How to update a jar file after change in manifest file and lib folder?

I have hadoop-1.0.3.jar. I made few changes in lib folder(add external jar) and manifest file now i want to rebuild jar file with name hadoop-1.0.4.jar.
How can I achieve this?
In the shell, run:
jar cvfm hadoop-1.0.4.jar Manifest.txt [list of files you want to package into your jar file]
You can run jar --help in the shell to check the different options available.
Basically, this particular command means:
-c: Create new jar file.
-v: Verbose output.
-f: Specify the packaged file name.
-m: Include the manifest file.
The rest should be fairly easy to understand (output name, manifest file, list of files to be packaged).

Problem in executing a built jar file in netbeans

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.

Categories