Drools / Java 8 compatibility - drools

I am trying to use Drools for rules validation, and I get an error with Java 8. As per the existing suggestions, I did upgrade to eclipse compiler to 4.4 and see the corresponding ecj-4.4.jar generated in my maven dependencies. However, I am still getting the wrong class format exception:
Caused by: org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException.
I tried using different versions of drools including 6.4.0.Final, 5.0.1 as well - but the issue persists.
I get this error when I try using the Stateless kie session but not with the stateful kie session.
Any thoughts?
Best Regards,
Sadhana

If you are using drools compiler dependency then change it below in pom.xml
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>${drools.version}</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
</exclusion>
</exclusions>
</dependency>
If you are using drools-spring dependency:
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-spring</artifactId>
<version>${drools-spring-version}</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
</exclusion>
</exclusions>
</dependency>
The error you are facing could be because there are multiple version of ecj jar and Java is picking the wrong one.

Related

Error with a excluded dependency in Spring Boot project: exclusion.artifactId with value '*' does not match a valid id pattern

If I want to build my project with maven package, I get the warning from Maven:
Some problems were encountered while building the effective model for
ch.mobi.ama:logcollector:jar:1.0.0-SNAPSHOT [WARNING]
'dependencyManagement.dependencies.dependency.exclusions.exclusion.artifactId'
for org.quartz-scheduler:quartz:jar with value '*' does not match a
valid id pattern. #
org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE,
c:\ieu.m2\repository\org\springframework\boot\spring-boot-dependencies\2.1.6.RELEASE\spring-boot-dependencies-2.1.6.RELEASE.pom,
line 2619, column 25
I've tried older Spring Boot versions. Version 2.1.5 had the same problem. With 2.1.4 there is no warning.
In line 2619 of the specified file spring-boot-dependencies-2.1.6.RELEASE.pom there is actually the following code:
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>${quartz.version}</version>
<exclusions>
<exclusion>
<artifactId>c3p0</artifactId>
<groupId>com.mchange</groupId>
</exclusion>
<exclusion>
<artifactId>*</artifactId>
<groupId>com.zaxxer</groupId>
</exclusion>
</exclusions>
</dependency>
Since the given code comes from Spring Boot, I can't influence it and have a bad feeling. Will my project be properly built? Do I have to go back to version 2.1.4? Do I have to report the problem to Spring Boot?
What can I do?
It's a maven new feature. Upgrade your maven to some version > 3.2.1.
https://maven.apache.org/docs/3.2.1/release-notes.html

drools dependencies for developing web app with embedded drools rules engine

I've developed a stand-alone drools application, with rules implemented via .drl files. I'm used the Eclipse IDE to develop the app. I want to embed this application in a web application using the tomcat web server package. I'd like to create a web app project in Eclipse and add the drools dependencies to the project, as needed. Which drools libraries/artifacts do I need to add to the project, e.g. kie and drools libraries/artifacts?
More specifically, if I create a maven-based web-app project using Eclipse. What other maven artifacts will I need to add to the POM for the drools capabilities?
The logic in the web application servlet will create a kie container and session, instantiate a set of Facts based on model definitions, insert the Facts into the session, fire the rules, and respond to the initial http request based on the results of rules evaluation.
I resolved the question I posed above a while ago. I'm posting an answer to close the question. I came up with a set of maven dependencies that I used to create a java servlet application that initializes and invokes an embedded DROOLS rules engine to process an http request. I've successfully tested the servlet-based application within a Tomcat server (v8.5). I used the Eclipse IDE to create the application as a maven-based project. The pom.xml file for the application has the following dependencies.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.servlet.jsp.jstl</artifactId>
<version>1.2.4</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>6.5.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>6.5.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>6.5.0.Final</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>

"Provider not a subtype" on org.eclipse.jetty.apache.jsp.JuliLog for Embedded Jetty

When using embedded jetty and started via
mvn jetty:run
The following exception is thrown:
Exception in thread "main" java.util.ServiceConfigurationError:
org.apache.juli.logging.Log: Provider org.eclipse.jetty.apache.jsp.JuliLog not a subtype
Here is the pom.xml snippets:
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>
<version>3.0.0.v201112011016</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.7.v20160115</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-websocket</artifactId>
<version>8.1.19.v20160209</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>8.1.19.v20160209</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.6</version>
</dependency>
Any pointers to a correctly configured embedded jetty (preferably also using websockets) appreciated.
Don't try to enable everything all at once.
Jetty is a highly modular system, you can pick and choose what you want to run. Nothing is mandatory by default, even the Server!
If you want examples of embedded jetty with websockets, consider reviewing the example projects that the Jetty project has put together at ...
https://github.com/jetty-project/embedded-websocket-echo-examples
Some advice:
Build up your requirements layer by layer
Start with basic websocket endpoint functionality (get this working first!)
then add slf4j + logback. (be sure you use an appropriate version, see the <scope>optional</scope> dependencies present in your previous layer before you choose a version of slf4j or logback). Test this like there is no tommorrow.
then add jsp support (as your error seems to indicate your desire for jsp support)

Adding rampart.mar to classpath via Maven

I have been trying to find a solution for this for several days, but with no avail.
I'm currently in the process of introducing Maven to some of my Java projects. One of them requires Axis2 and Rampart for WS Security.
I added all Axis2 and Rampart dependencies in pom.xml:
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.rampart</groupId>
<artifactId>rampart-core</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.rampart</groupId>
<artifactId>rampart-policy</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.rampart</groupId>
<artifactId>rampart-trust</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.rampart</groupId>
<artifactId>rampart</artifactId>
<version>1.5.2</version>
<type>mar</type>
</dependency>
When I import the project in Eclipse, rampart.mar is not there, and attempting to engage the rampart module on runtime causes a failure.
However, when I use maven-dependency-plugin to copy all dependencies to a specific repository, I see that the rampart mar file is there!
This makes me believe that this is a limitation in the Eclipse m2e plugin. Anyone stumbled upon this one before? I saw several similar questions on Stackoverflow that were left unanswered.

Problem adding commons-configuration to m2eclipse

I want to use the apache commons configuration jars in my Maven project.
When I add it using m2Eclipse it produces this:
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>20041012.002804</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
This seems fine but it then givers me the error:
Missing artifact resources:resources:jar:1.0:compile
Can anyone help please?
Looks like you need to choose a reliable version. That one seems to be a snapshot build. Here is the excerpt from my project.
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.6</version>
<type>jar</type>
<scope>compile</scope>
</dependency>