kjar是jboss brms对jar的一种扩展. In very few words, a KJAR is a standard JAR file that has some extra files included. A KJAR keeps the same .jar extension as a JAR file, because its basic file structure is identical to that of a JAR. “A JAR file is essentially a zip file that contains an optional META-INF directory.” 1 By contrast, a KJAR (“Knowledge artifact”) is specifically targeted for rules and processes which tend to be notated in XML or plain text.
- JAR: Does not need not be built according to any specific folder structure, as long as a META-INF directory is present at the top level
- KJAR: Conforms to the Maven Standard Directory Layout
- Extra files
- JAR: No specific files are required to be present
- KJAR: Must contain a META-INF/kmodule.xml file, which in turn must contain at least a
- Pre-compiled asset cache
- JAR: Any code which is to be pre-compiled into bytecode is the responsibility of the build service which generates the JAR.
- KJAR: Uses the KIE Maven plugin during build time, which automatically pre-compiles some rule and process assets into a cache (
META-INF/<kie-base-name>/kbase.cache). (This cache is not complete, but can improve performance when loading rules/processes.) If the cache is not created, all assets will be built at runtime.
- Deployment Descriptor (since v6.1)
- JAR: No specific configurations or deployment types are specified, though various other frameworks or standards (such as Java EE) may create their own standards.
- KJAR: If the file META-INF/kie-deployment-descriptor.xml exists, it is used automatically to determine various properties for executing rules and/or processes such as runtime strategy, event listeners, work item handlers, and more.
Nearly everything about a KJAR is really a targeted addition to a JAR file, so you can count on KJARs being almost entirely the same as JAR files. You can still use a MANIFEST.MF file to define package info, you can still use a beans.xml file to have CDI pick up classes, and you can still use popular files like logback.xml or log4j.xml for use with popular Java logging frameworks.
How is a KJAR made?
The primary difference between building a KJAR and building a standard JAR is that the KJAR has a
<plugin>for kie-maven-plugin in that same file.
What happens if I generate a JAR instead of a KJAR?
Officially, use of the KIE Maven plugin ensures that artifact resources are validated and pre-compiled, so use of that plugin is recommended at all times. However, if the rules/processes inside a KJAR are valid there are unlikely to be any execution problems whether they are running from a JAR or a KJAR. No kbase.cache would be created without the KIE Maven plugin 4, so it’s possible that users would encounter worse performance when attempting to run rules/processes from a JAR instead of a KJAR.