0

I am having hard time to find out how to define external jar in manifest.mf. When I use class path as shown below jar file does not get executed

Manifest-Version: 1.0
Sealed: true
Main-Class: org.test.MainClass
Class-Path: /Program Files (x86)/Testfolder/testlibrary/hibernate3.jar
 /Program Files (x86)/Testfolder/testlibrary/org.springframework.web-3.1.1.RELEASE.jar

When I give proper full class path as shown below, the Main class is not found or loaded

Manifest-Version: 1.0
Sealed: true
Main-Class: org.test.MainClass
Class-Path: D:/Program Files (x86)/Testfolder/testlibrary/hibernate3.jar
 D:/Program Files (x86)/Testfolder/testlibrary/org.springframework.web-3.1.1.RELEASE.jar

Does any one have any idea what am I doing wrong?

4
  • Never specify absolute paths, since you don't know the layout of the machine it's running on. Ship all the jars in a .zip or .tar.gz file, and make the paths relative to your main jar file, e.g. ../testlibrary/hibernate3.jar
    – Andreas
    Jul 16, 2019 at 0:56
  • You need to add hibernate3.jar into main jar classpath, and just add it as a Class-Path : hibernate3.jar
    – Youans
    Jul 16, 2019 at 0:57
  • Why are you including hibernate3.jar twice? Anyway, the main problem you have is that full path includes spaces. Easiest solution is to ensure relative paths don't have spaces, since space is a separator.
    – Andreas
    Jul 16, 2019 at 0:58
  • @Andreas My shared library is in different folder than jar file and I know the absolute path of the machine. Earlier I used to use shortcut directory without mentioning the drive as shown in the first part of manifest file. Now since short cut is not allowed I am trying to replace shortcut with Program Files (x86). For now I just want to properly give absolute path to the jar.
    – MR AND
    Jul 16, 2019 at 1:04

2 Answers 2

2

According to the documentation:

Class-Path Attribute

The manifest for an application can specify one or more relative URLs referring to the JAR files and directories for other libraries that it requires. These relative URLs are treated relative to the code base from which the containing application was loaded.

An application (or, more generally, a JAR file) specifies the relative URLs of the libraries that it requires with the manifest attribute Class-Path. This attribute lists the URLs to search for implementations of other libraries if they cannot be found on the host Java virtual machine. These relative URLs may include JAR files and directories for any libraries or resources needed by the application. Relative URLs not ending with a slash (/) are assumed to refer to JAR files. For example:

Class-Path: servlet.jar infobus.jar acme/beans.jar images/

At most one Class-Path header may be specified in a JAR file's manifest.

Currently, the URLs must be relative to the code base of the JAR file for security reasons. Thus, remote optional packages will originate from the same code base as the application.

Each relative URL is resolved against the code base from which the containing application or library was loaded. If the resulting URL is invalid or refers to a resource that cannot be found, then it is ignored.

2
  • Seems like I am really confused about the concept of classpath. Lets cay my jar file is in D:/ Program Files (*86)/test and I am using this path to execute the jar. How can I give relative path to the class path shown above.
    – MR AND
    Jul 16, 2019 at 1:29
  • I would really appreciate if you can show me how to use the relative path in the example I asked above
    – MR AND
    Jul 16, 2019 at 2:31
1

I found that I can also define absolute path as

Class-Path: file:///D:/Program%20Files%20(x86)

And this worked fine for me. The error regarding main class not found was related to the error in the class path and using absolute path as shown above will resolve the issue.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.