Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a jar without manifest file and main class?

Tags:

java

I have around 40 to 50 class files, and none have a main method or a manifest file. Now I have to create a JAR file from these files. How do I do this?

like image 430
Aditya Avatar asked Aug 14 '15 11:08

Aditya


People also ask

Can we create jar without main class?

Yes, but since it is a library this class will be available in it too. It just seems weird to add a class in that has no function whatsoever. just delete the Main class. You didn't need to create it in the first place.

Does a JAR file need a manifest?

The answer is the JAR file's manifest. The manifest is a special file that can contain information about the files packaged in a JAR file. By tailoring this "meta" information that the manifest contains, you enable the JAR file to serve a variety of purposes.

How do I fix no main manifest attribute?

It is easy to resolve this error in the Spring Boot project. To fix this error in the SB project, put the maven-plugin dependency under the <plugins> tag in the pom. xml file.


1 Answers

$ jar cf myjarfile.jar *.class

will create a jar file with a manifest containing info about the jar file, but without specifying a main class. A main class is not mandatory (e.g. if you're simply creating a library and not an application jar)

Or (perhaps more what you want), the M flag

$ jar cMf myjarfile.jar *.class

will create the jar file without the manifest.

like image 182
Brian Agnew Avatar answered Nov 06 '22 16:11

Brian Agnew