Class-Path
attribute in a Jar file Manifest exist. There are two ways to use this class:JarManifestUtilities.getDependencies(...)
methods allow to get the list of Jar files referenced in the Class-Path
property of a Jar file Manifest. It will return null if there is no Manifest in the Jar File. For example:Class-Path
property of the Jar file[1]
Class-Path
property of the Jar file will be taken into accountC:/my/directory/myJarFile.jar
jar file with the following Manifest:Class-Path: lib/theSupportLib.jar \ lib/theSecondLib.jarThe:
List<URL> list = JarManifestUtilities.getDependencies(<myJarFile>);Will return a list with two URLs:
C:/my/directory/lib/theSupportLib.jar
C:/my/directory/lib/theSecondLib.jar
JarManifestUtilities.checkDependencies(...)
methods allow to check that the Jar files referenced in the Class-Path
property of a Jar file Manifest exist.Class-Path
property of the Jar file will be taken into accountClass-Path
property of the Jar file Manifest existClass-Path
property of the Jar file Manifest existC:/my/project/dist/myJarFile.jar
jar file with the following Manifest:Class-Path: lib/theSupportLib.jar \ lib/theSecondLib.jarSuppose that we use an IDE where the libraries have been put in the
c:/my/project/lib/
directory, and the user dir is at the root of the project.File lib = new File(System.getLibrary("user.dir"), "lib"); URL libURL = lib.toURI().toURL(); boolean check = JarManifestUtilities.getDependencies(<myJarFile>, libURL, null);If the
lib
directory contains only theSupportLib.jar
and theSecondLib.jar
, the method will return true. If some Jar files are not present, or there are more, if will return false.
lib
directory with the following jar files:theSupportLib.jar
theSecondLib.jar
anotherLib.jar
lib
directory:File lib = new File(System.getLibrary("user.dir"), "lib"); URL libURL = lib.toURI().toURL(); boolean check = JarManifestUtilities.getDependencies(<myJarFile>, libURL, null);But it is possible to exclude the
anotherLib.jar
jar file with the following code:File lib = new File(System.getLibrary("user.dir"), "lib"); URL libURL = lib.toURI().toURL(); Set<String> excluded = new HashSet<>(); sexcluded.add("anotherLib.jar"); boolean check = JarManifestUtilities.getDependencies(<myJarFile>, libURL, excluded);In that case the method will return true.
Copyright 2019 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 licence