3

My MANIFEST.MF file looks like this

My main() prints the classpath -

  ClassLoader cl = ClassLoader.getSystemClassLoader();

        URL[] urls = ((URLClassLoader)cl).getURLs();

        for(URL url: urls){
            System.out.println(url.getFile());
        }

I am running jar file as-

java -jar "C:\Project-1.0-SNAPSHOT.jar"

When I run the jar file, I don't see any of the class paths set in manifest file. I only see the absolute path to C:\Project-1.0-SNAPSHOT.jar. Why is that so? Obviously code fails to run due to java.lang.NoClassDefFoundError error

Note that I am using maven-jar-plugin to create this jar file

user375868
  • 1,288
  • 4
  • 21
  • 45

1 Answers1

0

Hope you have line break at the end of the last line in your manifest file. If not then add a line break after the last line of Manifest.mf

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
  • @user375868 Are you sure dependency-jars in the path for the jars is working? Try to put the absolute path. – Juned Ahsan Jun 01 '13 at 17:50
  • The issue is that "Class-Path" mentioned in manifest is not being read when I run through java -jar. – user375868 Jun 01 '13 at 17:56
  • @user375868 I think the issue is that the path is not correct or generic to be referred from anywhere. When you use java -jar it will not understand the dependency-jars/xxx.jar path, which is related to maven. So you need to update the manifest to provide the path, which can be referred by java properly. Hence i said in my previous comment that try to give the absolute path of the jars in your manifest classpath variable. – Juned Ahsan Jun 01 '13 at 18:13
  • I am following this example- http://www.mkyong.com/maven/how-to-create-a-jar-file-with-maven/ - it should work, right? – user375868 Jun 01 '13 at 18:19
  • @user375868 so when you explode your jar, do you have the jars mentioned in your classpath under the directory dependency-jars? – Juned Ahsan Jun 01 '13 at 18:21
  • of course! see, the issue is class path is not being read from manifest file, if it was, my code in main would have printed it – user375868 Jun 01 '13 at 18:54
  • What are the contents of the Manifest file? – Nida Sahar Jun 01 '13 at 19:14