Bootstrap FreeKB - Java - Resolve "Failed to load Premain-Class manifest attribute"
Java - Resolve "Failed to load Premain-Class manifest attribute"

Updated:   |  Java articles

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.

Failed to load Premain-Class manifest attribute

 

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 "Failed to load Premain-Class manifest attribute" is being returned since the MANIFEST.MF file does not contain the Premain-Class attribute.

Manifest-Version: 1.0

 

Recompiling the JAR file so that the MANIFEST.MF file in the JAR contains the Premain-Class attribute should resolve this error. In this example, the Premain-Class is set to com.sample.Premain as the full path to the premain class in the JAR file.

Manifest-Version: 1.0
Premain-Class: com.sample.Premain

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter bd6727 in the box below so that we can be sure you are a human.