By default, this class only supports looking up official WebJars with the Maven group IDs of org.webjars.npm and org.webjars.
Custom WenJars can be registered by providing a META-INF/resources/webjars-locator.properties file.
Note: It is recommended, to add this file directly to the custom WebJar to ease the usage.
But for WebJars not providing the file, you can add a webjars-locator.properties to your project.
Example file (multiple WebJars can be provided, one per line):
mywebjar.version=3.2.1
anotherwebjar.version=1.4.3
As the lookup of all webjars-locator.properties files happens during the construction of the class
and the found versions are directly added to the cache, these property files can and will override versions
that otherwise would be looked up by version(String).
When multiple webjars-locator.properties files contain a version for the same WebJar, the one that has been found first wins.
The class is thread safe.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@Nullable StringBuilds the versioned path for a file of a WebJar within the standard WebJar classpath location (seeWEBJARS_PATH_PREFIX).@Nullable StringThis method tries to determine the groupId for a WebJar in the classpath.@Nullable StringBuilds the versioned path for a file of a WebJar relative to the standard WebJar classpath location (seeWEBJARS_PATH_PREFIX).@Nullable StringThis method tries to determine the available version for a WebJar in the classpath.
-
Field Details
-
WEBJARS_PATH_PREFIX
The path to where webjar resources live.- See Also:
-
-
Constructor Details
-
WebJarVersionLocator
public WebJarVersionLocator()
-
-
Method Details
-
fullPath
Builds the versioned path for a file of a WebJar within the standard WebJar classpath location (seeWEBJARS_PATH_PREFIX).The path is built by prefixing the versioned path built by
path(String, String)with the standard WebJars location classpath.See
path(String, String)for a detailed explanation of how the versioned file path is built.Note: This method does not perform any checks if the resulting path references an existing file.
- Parameters:
webJarName- The name of the WebJar, this is the directory in the standard WebJar classpath location, usually the same as the Maven artifact IDfilePath- The path to the file within the WebJar- Returns:
- The versioned path to the file in the classpath, if a version has been found, otherwise
null - See Also:
-
path
Builds the versioned path for a file of a WebJar relative to the standard WebJar classpath location (seeWEBJARS_PATH_PREFIX).The path is built by joining the
webJarName, the known version and thefilePath, if no version (from classpath checking) is known for the WebJar this method returnsnull.Note: In cases where the
filePathparameter already starts with the known version of the WebJar, the version will not be added again. But it is recommended that you do NOT include a hard-coded version when looking up WebJar file paths.// returns "bootstrap/3.1.1/css/bootstrap.css" locator.path("bootstrap", "css/bootstrap.css"); // returns "bootstrap/3.1.1/css/bootstrap.css" as well locator.path("bootstrap", "3.1.1/css/bootstrap.css"); // returns null, assuming there is no "unknown" WebJar locator.path("unknown", "some/file.css");Note: This method does not perform any checks if the resulting path references an existing file.
- Parameters:
webJarName- The name of the WebJar, this is the directory in the standard WebJar classpath location, usually the same as the Maven artifact IDfilePath- The path to the file within the WebJar- Returns:
- The versioned path relative to the standard WebJar classpath location, if a version has been found, otherwise
null - See Also:
-
version
This method tries to determine the available version for a WebJar in the classpath.For official WebJars, the version lookup is performed by checking for a
pom.propertiesfile for eitherNPMorPLAINWebJars withinMETA-INF/maven. The lookup result is cached.Custom WebJars can be registered by using a
webjars-locator.propertiesfile. SeeWebJarVersionLocatorfor details.- Parameters:
webJarName- The name of the WebJar, this is the directory in the standard WebJar classpath location, usually the same as the Maven artifact ID- Returns:
- The version of the WebJar, if found, otherwise
null - See Also:
-
groupId
This method tries to determine the groupId for a WebJar in the classpath.For official WebJars, the version lookup is performed by checking for a
pom.propertiesfile for eitherNPMorPLAINWebJars withinMETA-INF/maven. The lookup result is cached.Custom WebJars can be registered by using a
webjars-locator.propertiesfile. SeeWebJarVersionLocatorfor details.- Parameters:
webJarName- The name of the WebJar, this is the directory in the standard WebJar classpath location, usually the same as the Maven artifact ID- Returns:
- The groupId of the WebJar, if found, otherwise
null - See Also:
-