We have a Java application that uses Drools rulesets. We are using Drools 6.1.
The rules are available on the workbench repository. We want to see the changes in the results when we change the ruleset with Workbench. So, in our java code we added Kiescanner module that checks this machine periodically but we could not be successful.
Our Java Code
package com.sample;
import org.drools.compiler.kproject.ReleaseIdImpl;
import org.kie.api.KieBase;
import org.kie.api.KieServices;
import org.kie.api.builder.KieScanner;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import com.drools.project1.inputs;
/**
* This is a sample class to launch a rule.
*/
public class DroolsTest {
public static final void main(String[] args) {
try {
KieServices ks = KieServices.Factory.get();
ReleaseIdImpl releaseId = new ReleaseIdImpl("com.drools",
"project1", "LATEST");
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieScanner kieScanner = ks.newKieScanner(kieContainer);
kieScanner.start(1000L);
while (true) {
KieBase kBase = kieContainer.getKieBase();
KieSession kSession = kBase.newKieSession();
inputs types = new inputs();
types.setNum1(50);
kSession.insert(types);
kSession.fireAllRules();
kSession.destroy();
Thread.sleep(1000);
System.out.println("getNum2 = " + types.getNum2());
}
} catch (Throwable t) {
t.printStackTrace();
System.err.println(t);
System.err.println("Cause = " + t.getCause());
}
}
}
We created our pom.xml and settings.xml files in the following way.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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.sample</groupId>
<artifactId>DroolsMaven</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Drools :: Sample Maven Project</name>
<description>A sample Drools Maven project</description>
<distributionManagement>
<repository>
<id>drools</id>
<name>Internal Releases</name>
<url>http://foo.com/kie-drools-wb-distribution/maven2</url>
</repository>
</distributionManagement>
<dependencies>
<!-- CDI dependencies -->
<!-- END -->
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>6.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>javax.xml.parsers</groupId>
<artifactId>jaxp-api</artifactId>
<version>1.4.5</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.org.apache</groupId>
<artifactId>jaxp-ri</artifactId>
<version>1.4</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>
<version>1.3.6</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xerces</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.xml.rpc</artifactId>
<version>3.1.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.4</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.5</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.drools</groupId>
<artifactId>project1</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/project1-1.0.jar</systemPath>
</dependency>
</dependencies>
<repositories>
<repository>
<id>my-local-repo</id>
<url>file://${project.basedir}/src/main/webapp/WEB-INF/lib</url>
</repository>
</repositories>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.4</version>
</extension>
</extensions>
<finalName>NAME_OF_THE_GENERATED_WAR</finalName>
<plugins>
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>6.1.0.Final</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<project>
1.6
</project>
<source>1.6</source>
<target>1.6</target>
<encoding>Cp1254</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<encoding>Cp1254</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<outputDirectory>${basedir}/target/generatedWAR</outputDirectory>
<tasks>
<echo>Echo : This is maven-war-plugin</echo>
</tasks>
</configuration>
</plugin>
</plugins>
</build>
</project>
settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>C:\Devel\m2repo</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>guvnor-m2-repo</id>
<username>user</username>
<password>pass</password>
</server>
</servers>
<mirrors>
<mirror>
<id>guvnor-m2-repo</id>
<url>http://foo.com/kie-drools-wb-distribution/maven2</url>
<mirrorOf>*</mirrorOf>
</mirror>
<mirror>
<id>nexus</id>
<url>http://10.145.3.107:8081/nexus/content/groups/public</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>snapshots</id>
<url>http://10.145.3.107:8081/nexus/content/repositories/snapshots</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>profile-1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>drools</id>
<url>http://foo.com/kie-drools-wb-distribution/maven2</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
</repositories>
</profile>
<profile>
<id>a.profile</id>
<properties>
<a.property>this is a property</a.property>
</properties>
</profile>
<profile>
<id>b.profile</id>
<properties>
<b.property>this is another property</b.property>
</properties>
</profile>
</profiles>
<!-- activeProfiles | List of profiles that are active for all builds. | -->
<activeProfiles>
<activeProfile>profile-1</activeProfile>
</activeProfiles>
</settings>
On the other hand if we delete the latest version in the local repository or "resolver-status.properties" files when code is running, the new version is downloaded from remote machine to local automatically. However If we create a new version on Workbench, program doesn't detect it.
Could we made a missing description?
Thank you for your advices.