
Let's say the following is returned when attempting to start an application server (e,g, JBoss, Tomcat, WebSphere) or when attempting to run a Java application on the command line.
no main manifest attribute, in example.jar
If this is occurring with an application server, this typically means that the -javaagent option is being used to load one or more JAR files, something like this (setenv.sh on Tomcat example).
export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/path/to/example.jar"
If this is occurring on the command line, this probably means that one or more JAR files are being used, something like this.
/path/to/java -jar /path/to/foo.jar:/path/to/bar.jar
On a Linux system, the vi editor can be used to examine a JAR file. Or, the jar -tf command can be used.
~]# jar -tf foo.jar
META-INF/MANIFEST.MF
.classpath
.project
com/sample/Premain.class
com/sample/HelloWorld.class
Let's say the MANIFEST.MF file in the JAR contains the following. In this scenario, it most certainly makes sense that "no main manifest attribute" is being returned since the MANIFEST.MF file does not contain the Main-Class attribute.
Manifest-Version: 1.0
Recompiling the JAR file so that the MANIFEST.MF file in the JAR contains the Main-Class attribute should resolve this error.
Manifest-Version: 1.0
Main-Class: com.sample.HelloWorld
Notice in this example that the HelloWorld class in the com.sample package is being used as the Main Class. This assumes that HelloWorld.class contains something like public static void main(String[] args).
package com.sample;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Did you find this article helpful?
If so, consider buying me a coffee over at