JBoss.orgCommunity Documentation
Packaging is the process of assembling required assets into a single deployable unit, called a package, and configuring the package as necessary.
Some aspects of the configuration are also critical for authoring
assets, such as the import of model classes and the definition of global
variables. For example, you may add a model which has a class called
com.something.Hello
, you would then add import
com.something.Hello
in your package configuration and save the
change.
The package configuration screen is reached by clicking on the required package in the "Package Explorer" and then selecting the "Edit" tab.
The "imports" section of the package configuration screen allows you to import Java classes needed by your assets.
When a POJO Model file is uploaded it is scanned for classes and imports are automatically created.
Globals are DRL Global variables that can be accessed by rules. Please consult the Drools Expert documentation for details.
The "Basic View" of Imports and Globals is shown by default. This view allows either to be managed visually.
Imports or Globals can be inserted by clicking the [+] icon beside the applicable panel. Either can also be deleted by selecting the appropriate Import or Global and clicking the dustbin icon.
Category Rules allow you to set 'parent rules' for a category of rules. Any rules appearing in the given category will 'extend' the rule specified - i.e. inherit the conditions/left-hand-side.
To be able to take advantage of Category Rules you first need to define one or more categories. See the section relating to Categories for additional information.
Category Rules are defined on the Package screen.
By default a new package has zero Category Rules defined.
Click on the pencil icon beside "Category Rules" to show the Category Rule editor.
Select a Category. Rules belonging to this category will extend another single rule.
Enter the parent rule name in the "Will extend the rule called" TextBox. This is the rule that others, in the defined category, will extend.
Click OK.
Save the package to ensure changes made take effect when building the package.
Details of defined Category Rules are shown on the Package screen.
Click on the [-] icon to delete a Category Rule.
Example DRL achieved with Category Rules.
rule "BaseRule" dialect "mvel" when $a : Applicant( ) then end rule "ChildRule" extends "BaseRule" dialect "mvel" when Bankruptcy( ) then end
You can build a package by clicking on the button Build package. Any building errors (such as compilation errors) are shown, failing the build. You can chose to build the whole package or a subset of it (see next sections).
In cases of a large number of rules, all these operations can take some time.
If the build was successful, you can download the binary package as a pkg file. Also you will have the option to create a snapshot for deployment. You can also view the DRL that this package results in by clicking on the package source link.
If you wish to rebuild all packages in bulk, you can do that faster with the left menu Knowledge Bases, menu Create New, menu item Rebuild all packages binaries.
When building packages using the "Packages" feature you have the option to use a "selector". This selector will filter the list of rules that are built into the package.
Guvnor provides several built-in selectors which allow you to choose what assets form part of a package build according to asset's status and category.
You can use a custom selector if the built-in selector does not satisfy your requirement.
To configure a custom selector, you will need to "explode" the WAR file for Guvnor, and locate the
selectors.properties
file (note you can also put your own selectors.properties
file in the system classpath if you like). In this file, you will
find details on how you can configure a custom selector. The options are to use a DRL file, or the name of
a class that you have written (and which is available on the classpath). Classes must implement the
AssetSelector
interface. DRL files can also be used and there is an example one in the
selectors.properties
file). Each selector you configure has a unique name in this
properties file - and this is the name that you can use when building packages.
URLs are central to how built packages are provided. Guvnor provides packages via URLs (for download and use by the Knowledge Agent). These URLs take the form of:
http://<server>/guvnor-webapp/org.drools.guvnor.Guvnor/package/<packageName>/<packageVersion>
<packageName> is the name you gave the package. <packageVersion> is either the name of a snapshot, or "LATEST" (if its LATEST, then it will be the latest built version from the main package, not a snapshot). You can use these in the Knowledge Agent, or you can paste them into your browser and it will download them as a file.
Refer to the section on the Knowledge Agent for details on how you can use these URLs (and binary downloads) in your application, and how rules can be updated on the fly.
The above shows the Package Snapshots view. On the left there is a list of packages. Clicking on a specific package will show you a list of snapshots for that package (if any). From there you can copy, remove or view the assets contained within the snapshot. You can also compare one snapshot to another. Each snapshot is available for download or access via a URL for deployment.
As drools supports various configuration options for a package (such
as adding functions for "accumulate" etc), this can be done by adding a
X.package
or X.conf
file to the
package - files which contain name/value pairs in the "properties" style.
These will then be automatically added to the package configuration. See the
main drools documentation for all the things you can do.