I'm currently evaluating things using the 5.19 demo and would like to use a jar within rules. I'm grasping at straws as the documentation isn't completely clear on how to incorporate things, and am running into an error.
I've created a jar containing a simple class to access a database via JDBC from within an Method Table. I've added a Rules.xml to the deployment, and specified
What am I missing to at least have the CallProcs class found? Using a Code table has not helped, and adding an import statement to these are not allowed based on the errors returned.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've also tried adding the straight class, and jar to the project's files itself as well as the package name of the class, different paths, etc. The error persists.
Last edit: eb 2017-11-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
1) Put your jars in the lib folder, beside rules.xml. And use the following configuration in the rules.xml
<classpath><entrypath="lib/*.jar"/></classpath>
2) Add the following line in Environment table In the excel file:
Environment
import
com.example.CallProcs // to import CallProcs class from the .jar to OpenL rules
Regards, Yury.
P.S. Keep in mind that imported jars MUST NOT HAVE runtime dependencies on other libraries, such as Apache commons, Hibernate, Spring, CXF and etc. In that case OpenL classloader cannot load such jars.
Last edit: OpenL Tablets 2017-11-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I just found the Environment table requirement as well. If it could list this in the reference doc, section 6.1 Project Sources, it would make things a bit easier to follow. While I had tried to add a jar to a folder in the project, the folder would disappear after creation, and couldn't be selected when uploading a file. I see now that you have to add a file immediately to the folder by selecting the folder using the project pane, then upload file there.
Thank you for the heads up on the runtime dependencies. It just so happened that the MSSQL jdbc driver needed for the class was already in openl's classpath allowing this call to work.
While I was able to get this working, I feel this approach would be extremely inefficient due to the most basic DB call overhead. The use case was such that a rule would only be passed an initial bit of information to execute. It would then, based on conditional results, pull additional data for more evaluations.
Is there another way for OpenL to access a DB from rules which might be more efficient? The alternative is to send it all possible data it may need for an evalution, or call it through a service layer which would maintain what additional steps are needed depending on rule responses.
Thank you again
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
OpenL has to work with a variety of data providers so we don't built in all the options. We rely on the implementation team to add all the dependencies for this.
Once you built your layer to access the data from DB it can be used accross all the rules. It becomes your choice if it would be from within rules or external by providing all the data to rules.
It's a good suggestion to cross link the sections about jar dependencies management and how to enable them in rules. We need user to list classes in Environment table to avoid all the classes becoming availble in rules. It's a common scenario that very few classes are used as BAs and SMEs are primary users of OpenL
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
eb,
Did you find a nice way to get more data based on conditional results? we will need to make some http requests to get more data, where each request will cost us money, so we don't want to call it before any rule needs it. I was trying to make a jar with some methods that call those services, and using these methods on my rules, but maybe it wasnt the best choice, coz it seems to be locking threads.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm currently evaluating things using the 5.19 demo and would like to use a jar within rules. I'm grasping at straws as the documentation isn't completely clear on how to incorporate things, and am running into an error.
I've created a jar containing a simple class to access a database via JDBC from within an Method Table. I've added a Rules.xml to the deployment, and specified
The jar has been placed into:
C:\Program Files\openl\apache-tomcat-7.0.40\webapps\webservice\WEB-INF\lib
The Method Table, where CallProcs is a public class, and a public method getFieldInfo():
However, the following error always results:
What am I missing to at least have the CallProcs class found? Using a Code table has not helped, and adding an import statement to these are not allowed based on the errors returned.
I've also tried adding the straight class, and jar to the project's files itself as well as the package name of the class, different paths, etc. The error persists.
Last edit: eb 2017-11-21
Hi,
1) Put your jars in the lib folder, beside rules.xml. And use the following configuration in the rules.xml
2) Add the following line in Environment table In the excel file:
Regards, Yury.
P.S. Keep in mind that imported jars MUST NOT HAVE runtime dependencies on other libraries, such as Apache commons, Hibernate, Spring, CXF and etc. In that case OpenL classloader cannot load such jars.
Last edit: OpenL Tablets 2017-11-21
I just found the Environment table requirement as well. If it could list this in the reference doc, section 6.1 Project Sources, it would make things a bit easier to follow. While I had tried to add a jar to a folder in the project, the folder would disappear after creation, and couldn't be selected when uploading a file. I see now that you have to add a file immediately to the folder by selecting the folder using the project pane, then upload file there.
Thank you for the heads up on the runtime dependencies. It just so happened that the MSSQL jdbc driver needed for the class was already in openl's classpath allowing this call to work.
While I was able to get this working, I feel this approach would be extremely inefficient due to the most basic DB call overhead. The use case was such that a rule would only be passed an initial bit of information to execute. It would then, based on conditional results, pull additional data for more evaluations.
Is there another way for OpenL to access a DB from rules which might be more efficient? The alternative is to send it all possible data it may need for an evalution, or call it through a service layer which would maintain what additional steps are needed depending on rule responses.
Thank you again
OpenL has to work with a variety of data providers so we don't built in all the options. We rely on the implementation team to add all the dependencies for this.
Once you built your layer to access the data from DB it can be used accross all the rules. It becomes your choice if it would be from within rules or external by providing all the data to rules.
It's a good suggestion to cross link the sections about jar dependencies management and how to enable them in rules. We need user to list classes in Environment table to avoid all the classes becoming availble in rules. It's a common scenario that very few classes are used as BAs and SMEs are primary users of OpenL
eb,
Did you find a nice way to get more data based on conditional results? we will need to make some http requests to get more data, where each request will cost us money, so we don't want to call it before any rule needs it. I was trying to make a jar with some methods that call those services, and using these methods on my rules, but maybe it wasnt the best choice, coz it seems to be locking threads.