Class WebJarResolver
WebJarsMixin mount.
An asset is named groupId:artifactId:path (see asset(String, String, String)). The path is
relative to META-INF/resources/webjars/ and may contain VERSION_TOKEN, which is replaced with the
version read from the WebJar's own META-INF/maven/<groupId>/<artifactId>/pom.properties. The URL gets a
?v=<version> cache-buster, so a version bump in the app's pom changes every URL.
A missing WebJar, or a missing file in a present WebJar, throws IllegalStateException, so a page never
renders a tag that would 404. Versions and file checks are cached for the life of the class loader.
Example:
String
- Since:
- 10.0.0
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringBuilds an asset id.static Stringresolve(RestRequest req, String asset) Resolves an asset id to an absolute, cache-busted URL under theWebJarsMixinmount of the request's servlet.static StringresolvePath(String asset) Resolves an asset id to its file path underMETA-INF/resources/webjars/, checking that the file exists.static StringReturns the version of a WebJar on the classpath.
-
Field Details
-
WEBJARS_ROOT
Classpath root of every WebJar's files.- See Also:
-
VERSION_TOKEN
Placeholder in an asset path that is replaced with the WebJar's version.- See Also:
-
-
Method Details
-
asset
Builds an asset id.- Parameters:
groupId- The WebJar group id, e.g.org.webjars.artifactId- The WebJar artifact id, e.g.jquery.path- The file path underMETA-INF/resources/webjars/, optionally containingVERSION_TOKEN.- Returns:
- The asset id
groupId:artifactId:path.
-
version
Returns the version of a WebJar on the classpath.- Parameters:
groupId- The WebJar group id.artifactId- The WebJar artifact id.- Returns:
- The version from the WebJar's
pom.properties. - Throws:
IllegalStateException- If the WebJar isn't on the classpath or names no version.
-
resolvePath
Resolves an asset id to its file path underMETA-INF/resources/webjars/, checking that the file exists.- Parameters:
asset- The asset id (seeasset(String, String, String)).- Returns:
- The path with
VERSION_TOKENfilled in. - Throws:
IllegalArgumentException- If the asset id is malformed.IllegalStateException- If the WebJar or the file isn't on the classpath.
-
resolve
Resolves an asset id to an absolute, cache-busted URL under theWebJarsMixinmount of the request's servlet.- Parameters:
req- The in-flight request.asset- The asset id (seeasset(String, String, String)).- Returns:
- The URL.
-