Skip to content

Simple Genealogy Rules – part 2

August 27, 2013

This is the second part from the excerpts from the Skills421 (www.skills421.com) training course that I am currently developing.

In part 1 we identified the problem domain.  Here in part 2 we will create a simple Drools Project with which to implement our solution.

Creating the Geneology Project

Some of you may have noticed that I have spelled Genealogy wrong.  This is a deliberate act so that I can build this project step by step alongside my real Genealogy project.

So – here we go installing the incorrectly spelled Geneology Project.

I am going to assume you have downloaded Eclipse and Maven and installed both.  If not, then have a look on www.skills421.com for the Maven tutorial.  It will be appearing there some time tomorrow.

  • Open Eclipse and right click in the Project Explorer window.
  • From the popup menu select New -> Other -> Maven Project

009-New Project

Select Maven Project and click Next

010-New Project

Check the box to create a simple project and click Next

011-New Project

Enter the Group id as: com.skills421.training.drools
Enter Artifact Id as: Geneology

click Finish.

You can now see your project as a Maven project similar to that below:

012-New Project

Open the pom.xml file and change the view in the content panel to pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.skills421.training.drools</groupId>
  <artifactId>Geneology</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</project>

pom.xml

Adding the Drools Dependencies

We are going to use Drools 5.4.0.Final for this tutorial.

To find the dependency code navigate to http://mvnrepository.com/artifact/org.drools and click on the Last Version button for the top two entries – drools-compiler and drools-core.

This will display a list of version numbers, types and download buttons. Find the version 5.4.0.Final and click that.

The dependency will appear similar to this:

015-DroolsRepository

Cut and paste the dependency into your pom.xml.

Your final result will look like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.skills421.training.drools</groupId>
	<artifactId>Geneology</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<dependencies>
		<dependency>
			<groupId>org.drools</groupId>
			<artifactId>drools-compiler</artifactId>
			<version>5.4.0.Final</version>
		</dependency>
		<dependency>
			<groupId>org.drools</groupId>
			<artifactId>drools-core</artifactId>
			<version>5.4.0.Final</version>
		</dependency>
	</dependencies>
</project>

pom.xml

Take a look in your Project Explorer in the Maven Dependencies library folder and you will see the following:

016-DroolsRepository

This is everything we need to be able to build and run Drools Rules.

However, for testing, let’s do one more thing:

Install JUnit

Go back to your browser and enter: http://mvnrepository.com/artifact/junit 

Choose the latest release version of JUnit and copy the dependency into your pom.xml

Your pom will now look like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.skills421.training.drools</groupId>
	<artifactId>Geneology</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<dependencies>
		<dependency>
			<groupId>org.drools</groupId>
			<artifactId>drools-compiler</artifactId>
			<version>5.4.0.Final</version>
		</dependency>
		<dependency>
			<groupId>org.drools</groupId>
			<artifactId>drools-core</artifactId>
			<version>5.4.0.Final</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
		</dependency>
	</dependencies>
</project>

pom.xml

This will download the JUnit jars and add them to your Maven Dependencies Library folder.

Next Steps

We have now set up our project so in the next part we will build create the Fact objects that will represent the people in our genealogy tree, and some simple extensions to some of the standard Java classes to make life simpler for us as we implement the rules.

Advertisements

From → Tutorials

2 Comments
  1. Reblogged this on Skills421.

Trackbacks & Pingbacks

  1. Moving Geneology to Drools 6.0 | Drools Rules

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: