For test purposes, I created the following Java class
package com.toysrus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SuperNewApp { static Logger LOGGER = LoggerFactory.getLogger(SuperNewApp.class); public static void main(String[] args) { LOGGER.info( "starting SuperNewApp" ); System.out.println("This is SuperNewApp"); } }
Main-Class: com.toysrus.SuperNewApp Class-Path: lib/slf4j-api-1.7.2.jar lib/slf4j-jdk14-1.7.2.jar
$ javac -cp lib/slf4j-api-1.7.2.jar -sourcepath src/java/com/toysrus -d bin src/java/com/toysrus/SuperNewApp.java $ jar cvfm SuperNewApp.jar Manifest.txt lib/* -C bin/ .
Manifest-Version: 1.0 Created-By: 1.8.0-ea (Oracle Corporation) Main-Class: com.toysrus.SuperNewApp
$ java -jar SuperNewApp.jar Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at com.toysrus.SuperNewApp.(SuperNewApp.java:7) Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:359) at java.net.URLClassLoader$1.run(URLClassLoader.java:348) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:347) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 1 more $
$ java -cp SuperNewApp.jar:lib/slf4j-api-1.7.2.jar:lib/slf4j-jdk14-1.7.2.jar com.toysrus.SuperNewApp Jun 20, 2014 1:26:43 PM com.toysrus.SuperNewApp main INFO: starting SuperNewApp This is SuperNewApp $
Okay, I got it working. The manifest seems to require a trailing space before the newline after each library listed in the classpath. I originally had a carriage return and started each subsequent new line with a space but, in order for this to work, a trailing space is also required.
$ jar cvfm SuperNewApp.jar Manifest.txt lib/* -C bin/ . added manifest adding: lib/slf4j-api-1.7.2.jar(in = 26083) (out= 22615)(deflated 13%) adding: lib/slf4j-jdk14-1.7.2.jar(in = 7845) (out= 6465)(deflated 17%) adding: .DS_Store(in = 6148) (out= 178)(deflated 97%) adding: com/(in = 0) (out= 0)(stored 0%) adding: com/toysrus/(in = 0) (out= 0)(stored 0%) adding: com/toysrus/SuperNewApp.class(in = 723) (out= 448)(deflated 38%)
$ java -jar SuperNewApp.jar Jun 20, 2014 1:46:26 PM com.toysrus.SuperNewApp main INFO: starting SuperNewApp This is SuperNewApp $