Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java jar - no main manifest attribute

Tags:

java

jar

manifest

I'm aware that jar files should have a manifest.mf Main-Class: attribute in order to have an entry point and make the jar file runnable. Now, I have a jar file that I've built per below. The classes are all part of the burrito package. My MANIFEST.MF file looks like:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.1
Created-By: 1.7.0_51-b13 (Oracle Corporation)
Class-Path: 
X-COMMENT: Main-Class will be added automatically by build
Main-Class: burrito.Main

, and when I try to build and execute via the following:

jar -cvf Burrito.jar Customer.class Main.class Server
.class Store.class MANIFEST.MF
*added manifest
adding: Customer.class(in = 2800) (out= 1424)(deflated 49%)
adding: Main.class(in = 1147) (out= 757)(deflated 34%)
adding: Server.class(in = 3954) (out= 2094)(deflated 47%)
adding: Store.class(in = 3950) (out= 2190)(deflated 44%)
adding: MANIFEST.MF(in = 203) (out= 158)(deflated 22%)*

I get:

Burrito.jar

*java -jar Burrito.jar
no main manifest attribute, in Burrito.jar*

I've tried various ways, also trying the -m switch (cvfm). I've attempted the following:

java -cp Burrito.jar burrito.Main

as well as

java -cp Burrito.jar Main

, which both tell me Error: Could not find or load main class

I've been poring over forums, and I can't seem to 'Google' my way to a solution here. Of course the Netbeans jar works, but I need to build my own. I've peeked at the Netbeans jar, and I see that I have two folders, burrito and META-INF. Of course, the manifest file is in the META-INF folder, and the burrito folder contains the class files. I'm not sure exactly to mimic this, and I would be happy to simply get this program to run.

Any pointers/hints?

like image 267
patricio2626 Avatar asked Sep 27 '22 08:09

patricio2626


1 Answers

You want something like this:

jar -cvfm Burrito.jar MANIFEST.MF burrito/Customer.class burrito/Main.class burrito/Server.class burrito/Store.class

The first argument after the options correspond to the f flag (the file to create), and the second argument corresponds to the m flag (the manifest file), and all the other arguments are the files to add to the JAR. You have to ensure the folder structure in the JAR matches the Java package, so if burrito.Main is the class, then you need burrito/Main.class in the JAR, and similarly for the other classes.

like image 113
Brett Kail Avatar answered Oct 13 '22 02:10

Brett Kail