For a project, I need to import the GSON library, despite of these steps found on different topics, I still have the error NoClassDefFoundError...
Step 1 : in the BuildPath, I add the library as an external JARs
Step 2 : in Order and Export, I check the library
So, if anyone has the solution, thank you in advance for your answers ! ;)
More Informations :
package ummisco.gama.webgl;
import com.google.gson.Gson;
public class SceneReceiver {
private final static SceneReceiver instance = new SceneReceiver();
private boolean canReceive = true;
public static SceneReceiver getInstance() {
return instance;
}
private SceneReceiver() {
}
public void receive(final SimpleScene scene) {
reception(false);
try {
Gson gson = new Gson();
String sceneSend = gson.toJson(scene);
System.out.println(sceneSend);
} catch (Exception e) {
System.out.println(e.getMessage());
}
reception(true);
}
private void reception(boolean canReceive) {
this.canReceive = canReceive;
}
public boolean canReceive() {
return canReceive;
}
}
Here the stacktrace :
Exception in thread "Thread-14" java.lang.NoClassDefFoundError: com/google/gson/Gson
at ummisco.gama.webgl.SceneReceiver.receive(SceneReceiver.java:28)
at ummisco.gama.opengl.scene.ModelScene.endDrawingLayers(ModelScene.java:232)
at ummisco.gama.opengl.scene.SceneBuffer.endUpdatingScene(SceneBuffer.java:74)
at ummisco.gama.opengl.JOGLRenderer.endDrawingLayers(JOGLRenderer.java:713)
at msi.gama.outputs.display.LayerManager.drawLayersOn(LayerManager.java:182)
at ummisco.gama.opengl.SWTOpenGLDisplaySurface.updateDisplay(SWTOpenGLDisplaySurface.java:168)
at ummisco.gama.ui.views.displays.LayeredDisplayView$11.run(LayeredDisplayView.java:673)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.google.gson.Gson cannot be found by ummisco.gama.opengl_1.7.0.qualifier
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:439)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 8 more
Related
I'm attempting my first Java project and would like to use Gson to read in a Json file (which I generated from a spreadsheet) to then be added as class objects.
import com.google.gson.Gson;
public class Init {
public static void main(String[] args) {
// TODO Auto-generated method stub
Gson gson = new Gson();
FileReader fr = null;
try {
fr = new FileReader("Log_Model.json");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Object json = gson.fromJson(fr, Item[].class);
//https://futurestud.io/tutorials/gson-mapping-of-arrays-and-lists-of-objects
System.out.println(json);
}
When I run this I get the following error,
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gson/Gson
at relog.Init.main(Init.java:13)
Caused by: java.lang.ClassNotFoundException: com.google.gson.Gson
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
I'm using Eclipse which is installed in my User folder on Windows 7, the gson jar is placed in the project folder and I've added it to the build path.
Adding GSON to project :
Open Windows >preferences in the Eclipse menu, and navigate to the
Java >Build path > User Libraries tab. Click new and enter a new User
Library name: like “gson_lib” and hit ok. With “gson_lib” selected
press Add External JARs and find the gson-2.8.6.jar you downloaded.
Apply and Close.
First create class JSON Schema. You can make class structure with JsonToSchema
Example :
public class User {
public String name, email;
public int age;
public User(String name, String email, int age){
this.name = name;
this.email = email;
this.age = age;
}
}
Code :
import com.google.gson.*;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
public class Main {
private static final Type USER_TYPE = new TypeToken<List<User>>() {}.getType();
public static void main(String[] args) {
JsonReader reader = new JsonReader(new FileReader("user.json"));
// change the JSON string to Object
Gson gson = new GsonBuilder().create();
List<User> data = gson.fromJson(reader, USER_TYPE); // contains the whole user list
data.toScreen(); // prints to screen some values
}
}
Error is :
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.agile.pc.cmserver.base.CMLogger.setLogClass(CMLogger.java:39)
at com.agile.util.log.CMLogFactory.getLogger(CMLogFactory.java:77)
at com.agile.util.exception.AppException.<clinit>(AppException.java:28)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.proxy.$Proxy23.<clinit>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.reflect.Proxy.newProxyInstance(Unknown Source)
at com.agile.api.pc.EJBRemoteProxy.createRemoteProxy(EJBRemoteProxy.java:60)
at com.agile.api.pc.EJBLookup.getRemoteInterface(EJBLookup.java:1012)
at com.agile.api.pc.EJBLookup.getRemoteInterface(EJBLookup.java:959)
at com.agile.api.pc.EJBLookup.getChangeSession(EJBLookup.java:309)
at com.agile.api.pc.change.Change.getBean(Change.java:106)
at com.agile.api.pc.RouteObject$GetStatusAction.doSdkAction(RouteObject.java:2926)
at com.agile.api.common.SDKAction.run(SDKAction.java:23)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:368)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:163)
at weblogic.security.Security.runAs(Security.java:61)
at com.agile.api.common.WebLogicAuthenticator.doAs(WebLogicAuthenticator.java:111)
at com.agile.api.common.Security.doAs(Security.java:54)
at com.agile.api.common.Security.doAs(Security.java:109)
at com.agile.api.pc.RouteObject.getStatus(RouteObject.java:1206)
at com.gehc.extensions.px.CreateChildSCN.doAction(CreateChildSCN.java:39)
at com.gehc.extensions.px.CreateChildSCN.main(CreateChildSCN.java:124)
Caused by: java.lang.NullPointerException
at org.apache.logging.log4j.util.ProviderUtil.validVersion(ProviderUtil.java:142)
at org.apache.logging.log4j.util.ProviderUtil.loadProvider(ProviderUtil.java:80)
at org.apache.logging.log4j.util.ProviderUtil.<init>(ProviderUtil.java:66)
at org.apache.logging.log4j.util.ProviderUtil.lazyInit(ProviderUtil.java:124)
at org.apache.logging.log4j.util.ProviderUtil.hasProviders(ProviderUtil.java:108)
at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:89)
... 27 more
Javafile:
import java.util.ResourceBundle;
import org.apache.log4j.Logger;
import com.agile.api.APIException;
import com.agile.api.IAgileSession;
import com.agile.api.IChange;
import com.agile.api.IDataObject;
import com.agile.api.INode;
import com.agile.px.ActionResult;
import com.agile.px.ICustomAction;
import com.gehc.common.core.CreateChildSCN_BO;
import com.gehc.common.pxconstants.GEHC_SCNConstants;
import com.gehc.common.pxutil.SDKUtil;
import com.gehc.common.pxutil.Util;
public class CreateChildSCN implements ICustomAction {
private static ResourceBundle objResourceBundle = ResourceBundle.getBundle("GEHCCreateChildSCN");
private static Logger objLogger = Logger.getLogger(CreateChildSCN.class);
public ActionResult doAction(IAgileSession aSession, INode actionNode,
IDataObject currentObject){
Util.initAppLogger(CreateChildSCN.class, Util.getLogFileName());
StringBuffer pxMessage = new StringBuffer();
try
{
IChange objChange = (IChange)currentObject;
String strChangeStatus = objChange.getStatus().toString();
IAgileSession objAgileSession = null;
String strUser = aSession.getCurrentUser().toString();
objLogger.info("Session with Logged on User..::"+aSession.getCurrentUser().toString());
objAgileSession = SDKUtil.getAgileSession(objResourceBundle
.getString("AGILE_USER"), objResourceBundle
.getString("AGILE_PASSWORD"), objResourceBundle
.getString("AGILE_URL"));
if(!(strUser.equals(objResourceBundle.getString("CURRENT_USER")))){
if(strChangeStatus.equals(objResourceBundle.getString("ECO_WORKFLOW_STATUS"))
|| strChangeStatus.equals(objResourceBundle.getString(("ECR_WORKFLOW_STATUS")))){
String suppliers = objChange.getValue(GEHC_SCNConstants.SCN_SUPPLIER_NAME).toString();
String supplierGroup = objChange.getValue(GEHC_SCNConstants.SCN_SUPPLIER_USER_GROUPS).toString();
//Checking for the suppliers presence
if("".equals(suppliers) && "".equals(supplierGroup)){
CreateChildSCN_BO objChildSCNBO = new CreateChildSCN_BO();
pxMessage.append(objChildSCNBO.createSCNs(objAgileSession, objChange));
}else{
pxMessage.append(objResourceBundle.getString("MESSAGE_ERROR_SUPPLIER_NAME_VALUE"));
objLogger.info(objResourceBundle.getString("MESSAGE_ERROR_SUPPLIER_NAME_VALUE"));
System.out.println(objResourceBundle.getString("MESSAGE_ERROR_SUPPLIER_NAME_VALUE"));
}
}else{
//System.out.println(objResourceBundle.getString("MESSAGE_ERROR_WORKFLOW_CRITERIA"));
pxMessage.append(objResourceBundle.getString("MESSAGE_ERROR_WORKFLOW_CRITERIA"));
} objLogger.info(objResourceBundle.getString("MESSAGE_ERROR_WORKFLOW_CRITERIA"));
}else{
//System.out.println(objResourceBundle.getString("MESSAGE_ERROR_INVALID_USER_LOGIN"));
pxMessage.append(objResourceBundle.getString("MESSAGE_ERROR_INVALID_USER_LOGIN"));
objLogger.info(objResourceBundle.getString("MESSAGE_ERROR_INVALID_USER_LOGIN"));
}
}catch (Exception apiEx){
apiEx.printStackTrace();
System.out.println(objResourceBundle.getString("MESSAGE_ERROR_UNABLE_TO_DO ") + apiEx);
pxMessage.append(objResourceBundle.getString("MESSAGE_ERROR_UNABLE_TO_DO"));
objLogger.error(objResourceBundle.getString("MESSAGE_ERROR_UNABLE_TO_DO"));
}
return new ActionResult(ActionResult.STRING, pxMessage.toString());
}
/**
* For Stand alone Only
* Invokes the doAction method
*/
public static void main(String[] args) {
CreateChildSCN objSCRValidation = null;
String strNumber = null;
IAgileSession objAgileSession = null;
IChange objChange = null;
ResourceBundle objResources = ResourceBundle.getBundle("GEHCCreateChildSCN");
Logger objLogger = Logger.getLogger(CreateChildSCN.class);
try {
objSCRValidation = new CreateChildSCN();
Util.initAppLogger(CreateChildSCN.class, Util.getLogFileName());
strNumber = "SCN-0043018";
// Establish session
/*objAgileSession = SDKUtil.getAgileSession(objResources
.getString("AGILE_USER"), objResources
.getString("AGILE_PASSWORD"), objResources
.getString("AGILE_URL"));*/
objAgileSession = SDKUtil.getAgileSession("xxx","xxxx","xxxxxxxxx");
System.out.println("created session");
// Load the objChange
//System.out.println(" Object:: " + objChange.getName());
objChange = (IChange) objAgileSession
.getObject(IChange.OBJECT_TYPE, strNumber);
objSCRValidation
.doAction(objAgileSession, null, objChange);
} catch (APIException e) {
System.out.println("Error log from main thread ::: " + e);
objLogger.error(objResources.getString("SESSION_FAILED") + Util.exception2String(e));
}
}
}
And also it contains properties files where we defined logger details like path and file name of log file and logger initialization like log4j.category.com.xxx.common.util.SDKUtil = debug, XLogger
Here we are using Log4.jar api initialized in classpath.
Any help here is highly appreciated.
Thanks,
Himachandra.
if you look at the code for at org.apache.logging.log4j.util.ProviderUtil.validVersion(ProviderUtil.java:142), it looks like a bug in Log4J:
private static boolean validVersion(final String version) {
for (final String v : COMPATIBLE_API_VERSIONS) {
if (version.startsWith(v)) {
return true;
}
}
return false;
}
In that library, if (version.startsWith(v)) should be if (v.startsWith(version)) since version is nullable but v is never null.
Try using a newer version of log4j that does not have this bug.
I did not see this issue in version:
2.11.2
I saw this issue in versions:
2.6.2 (java.lang.NullPointerException at org.apache.logging.log4j.util.ProviderUtil.validVersion(ProviderUtil.java:142))
2.8.2 (java.lang.NullPointerException at org.apache.logging.log4j.util.ProviderUtil.validVersion(ProviderUtil.java:142))
2.10.0 (java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil)
Changing the version was a quick fix for me. However, it does not fix the underlying root cause. For me, I think it was some strange interaction between junit-log4j-jmockit that allowed the version to be null. If I ran tests in a different order, I had no issue.
I'm using Drools 5.5.0-Final and, suddenly, I have this exception
I put all the libraries again in my project, but the result is the same
org.drools.RuntimeDroolsException: Class not found for evaluator definition: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:136)
at org.drools.compiler.PackageBuilderConfiguration.buildEvaluatorRegistry(PackageBuilderConfiguration.java:550)
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:196)
at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:170)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:300)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:228)
at org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl.newKnowledgeBuilder(KnowledgeBuilderFactoryServiceImpl.java:34)
at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:46)
at com.drools.optimizer.AppExpertSystem.readKnowledgeBase(AppExpertSystem.java:130)
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:115)
at com.drools.optimizer.AppExpertSystem.<init>(AppExpertSystem.java:46)
at eventlauncher.OptimizerLauncher.NuevoEscenario(OptimizerLauncher.java:57)
at eventlauncher.DemoPruebas.main(DemoPruebas.java:18)
Caused by: java.lang.ClassNotFoundException: Unable to load class: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:92)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:132)
... 12 more
Exception in thread "main" java.lang.RuntimeException: org.drools.RuntimeDroolsException: Class not found for evaluator definition: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:122)
at com.drools.optimizer.AppExpertSystem.<init>(AppExpertSystem.java:46)
at eventlauncher.OptimizerLauncher.NuevoEscenario(OptimizerLauncher.java:57)
at eventlauncher.DemoPruebas.main(DemoPruebas.java:18)
Caused by: org.drools.RuntimeDroolsException: Class not found for evaluator definition: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:136)
at org.drools.compiler.PackageBuilderConfiguration.buildEvaluatorRegistry(PackageBuilderConfiguration.java:550)
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:196)
at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:170)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:300)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:228)
at org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl.newKnowledgeBuilder(KnowledgeBuilderFaorg.drools.RuntimeDroolsException: Class not found for evaluator definition: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:136)
at org.drools.compiler.PackageBuilderConfiguration.buildEvaluatorRegistry(PackageBuilderConfiguration.java:550)
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:196)
at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:170)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:300)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:228)
at org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl.newKnowledgeBuilder(KnowledgeBuilderFactoryServiceImpl.java:34)
at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:46)
at com.drools.optimizer.AppExpertSystem.readKnowledgeBase(AppExpertSystem.java:130)
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:115)
at com.drools.optimizer.AppExpertSystem.<init>(AppExpertSystem.java:46)
at eventlauncher.OptimizerLauncher.NuevoEscenario(OptimizerLauncher.java:57)
at eventlauncher.DemoPruebas.main(DemoPruebas.java:18)
Caused by: java.lang.ClassNotFoundException: Unable to load class: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:92)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:132)
... 12 more
Exception in thread "main" java.lang.RuntimeException: org.drools.RuntimeDroolsException: Class not found for evaluator definition: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:122)
at com.drools.optimizer.AppExpertSystem.<init>(AppExpertSystem.java:46)
at eventlauncher.OptimizerLauncher.NuevoEscenario(OptimizerLauncher.java:57)
at eventlauncher.DemoPruebas.main(DemoPruebas.java:18)
Caused by: org.drools.RuntimeDroolsException: Class not found for evaluator definition: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:136)
at org.drools.compiler.PackageBuilderConfiguration.buildEvaluatorRegistry(PackageBuilderConfiguration.java:550)
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:196)
at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:170)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:300)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:228)
at org.drools.builder.impl.KnowledgeBuilderFactoryServiceImpl.newKnowledgeBuilder(KnowledgeBuilderFactoryServiceImpl.java:34)
at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:46)
at com.drools.optimizer.AppExpertSystem.readKnowledgeBase(AppExpertSystem.java:130)
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:115)
... 3 more
Caused by: java.lang.ClassNotFoundException: Unable to load class: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:92)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:132)
... 12 morectoryServiceImpl.java:34)
at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:46)
at com.drools.optimizer.AppExpertSystem.readKnowledgeBase(AppExpertSystem.java:130)
at com.drools.optimizer.AppExpertSystem.loadKnowledgeBase(AppExpertSystem.java:115)
... 3 more
Caused by: java.lang.ClassNotFoundException: Unable to load class: org.drools.base.evaluators.EqualityEvaluatorsDefinition
at org.drools.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:92)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.drools.base.evaluators.EvaluatorRegistry.addEvaluatorDefinition(EvaluatorRegistry.java:132)
... 12 more
My code is:
import com.answare.backendconnection.RESTConnection;
import com.answare.dataModel.ActionANS;
import com.answare.dataModel.CrisisContextANS;
import com.answare.db.QueriesDB;
import com.answare.settings.CTES;
import com.drools.utils.Event;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseConfiguration;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.*;
import org.drools.conf.EventProcessingOption;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
import java.sql.SQLException;
/**
* This is the class that launch Expert System.
*/
public class AppExpertSystem {
StatefulKnowledgeSession ksession;
DSS_ANS optimizerDSS_ANS;
Event event;
RESTConnection restConnection;
public AppExpertSystem() {
loadKnowledgeBase();
optimizerDSS_ANS = new DSS_ANS(ksession);
event = new Event();
event.setNewEvent(true);
}
public AppExpertSystem(RESTConnection restConnection){
loadKnowledgeBase();
event = new Event();
event.setNewEvent(true);
this.restConnection = restConnection;
}
private void loadKnowledgeBase() {
// load up the knowledge base
KnowledgeBase kbase;
try {
kbase = readKnowledgeBase();
ksession = kbase.newStatefulKnowledgeSession();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource(CTES.RULES),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
KnowledgeBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
config.setOption(EventProcessingOption.STREAM );
return kbase;
}
public String executeMessage(CrisisContextANS crisisContext) {
try {
storeInDatabaseCrisis(crisisContext,true);
ksession.setGlobal("optimizerDSS", optimizerDSS_ANS);
ksession.insert(crisisContext);
this.event.setType("CrisisContextANS");
ksession.insert(this.event);
int num = ksession.fireAllRules();
if (num != 0) {
this.event.setNewEvent(false);
return ("Run OK from Expert System");
}
return ("");
} catch (Throwable t) {
t.printStackTrace();
return ("Run NOT OK Expert System");
}
}
}
And the exception is in the method readKnowledgeBase(), in line
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
The only thing that I'm doing is to call to AppExpertSystem constructor :(
Any idea?
Thanks!
This class is gone from the 5.5.0.Final distribution. It was present in 5.3.0 and 5.4.0 (jar: drools-core.jar), presumably also earlier.
org.drools.base and ...evaluators wasn't part of the stable API in 5.3 and 5.4, so using it was risky.
If you post how your code is using that class, s.o. might come up with a way to work around this mishap.
Class org.drools.base.evaluators.EqualityEvaluatorsDefinition is typically configured into the builder by including a line
drools.evaluator.equality = org.drools.base.evaluators.EqualityEvaluatorsDefinition
in a file "drools.packagebuilder.conf" in the working directory, your home directory or on some jar's META-INF drools.default.packagebuilder.conf, or on a file pointed to by a system property "drools.packagebuilder.conf".
I am learning the Luaj library and I am trying to implement the hyperbolic example in a unit test:
#Test
public void testHyperbolicLuaScriptExample() throws Exception {
URL luaScriptUrl = Thread.currentThread().getContextClassLoader().getResource("hyperbolic.lua");
Assert.assertNotNull(luaScriptUrl);
String luaScriptUrlPath = luaScriptUrl.getPath();
File luaScriptFile = new File(luaScriptUrlPath);
FileInputStream luaScriptFileInputStream = new FileInputStream(luaScriptFile);
Prototype luaScriptPrototype = LuaC.instance.compile(luaScriptFileInputStream, "");
Globals luaScriptStandardGlobals = JsePlatform.standardGlobals();
LuaClosure luaClosure = new LuaClosure(luaScriptPrototype, luaScriptStandardGlobals);
LuaValue luaValue = luaClosure.call();
}
hyperbolic.java is constructed as per the example
import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.*;
public class hyperbolic extends TwoArgFunction {
public hyperbolic() {}
public LuaValue call(LuaValue moduleName, LuaValue environment) {
LuaValue library = tableOf();
library.set("sinh", new sinh());
library.set("cosh", new cosh());
environment.set("com.apple.aide.lua.hyperbolic", library);
return library;
}
static class sinh extends OneArgFunction {
public LuaValue call(LuaValue x) {
return LuaValue.valueOf(Math.sinh(x.checkdouble()));
}
}
static class cosh extends OneArgFunction {
public LuaValue call(LuaValue x) {
return LuaValue.valueOf(Math.cosh(x.checkdouble()));
}
}
}
And the in hyberbolic.lua
require 'hyperbolic'
return {"x", hyperbolic.sinh(0.5), "y", hyperbolic.cosh(0.5)}
However the test produces the following error
org.luaj.vm2.LuaError: #hyperbolic.lua:3 loop or previous error loading module 'hyperbolic'
at org.luaj.vm2.LuaValue.error(Unknown Source)
at org.luaj.vm2.lib.PackageLib$require.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.call(Unknown Source)
at org.luaj.vm2.lib.PackageLib$require.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.call(Unknown Source)
at com.example.LuaScriptExecutionTest.testHyperbolicLuaScriptExample(LuaScriptExecutionTest.java:52)
What does this error mean and how do I fix it?
And the in hyberbolic.lua (sic, should be hyperbolic)
require 'hyperbolic'
You require a module with the same name as the file in which require happens, which leads to a loop (that's what the error message is about). Simply rename the current file (hyperbolic.lua) and the error should go away.
I have problems indexing table/collection using jcouchdb. Actually it looks very simple but After some researches i dont know where the problem is or maybe i just blind. I followed the official test class:
https://code.google.com/p/orient/source/browse/trunk/tests/src/test/java/com/orientechnologies/orient/test/database/auto/ClassIndexTest.java
Take a look on the follwing code:
public class TestIndex {
public static final String dbname = "indextest";
public static final String colname = "object";
public static final String indexAttribute = "ATTR1";
public static void main(String[] args)
{
//ODatabaseDocumentTx db = new ODatabaseDocumentTx ("local:/tmp/databases/" + dbname).create();
ODatabaseDocumentTx db = new ODatabaseDocumentTx ("local:/tmp/databases/orienttestdb");
db.open("admin", "admin");
try {
if(db.getMetadata().getSchema().existsClass(colname))
db.getMetadata().getSchema().dropClass(colname);
OClass object = db.getMetadata().getSchema().getOrCreateClass((colname));
object.createProperty(indexAttribute, OType.INTEGER);
object.createIndex(colname, OClass.INDEX_TYPE.NOTUNIQUE, indexAttribute);
db.getMetadata().getSchema().save();
}
catch(Exception e){
e.printStackTrace();
}
finally{
db.close();
}
}
}
I always get the following exception:
Exception in thread "main" java.util.ServiceConfigurationError: com.orientechnologies.orient.core.index.OIndexFactory: Provider com.orientechnologies.orient.core.index.hashindex.local.OHashIndexFactory could not be instantiated: java.lang.NoSuchFieldError: UNIQUE_HASH
at java.util.ServiceLoader.fail(Unknown Source)
at java.util.ServiceLoader.access$100(Unknown Source)
at java.util.ServiceLoader$LazyIterator.next(Unknown Source)
at java.util.ServiceLoader$1.next(Unknown Source)
at com.orientechnologies.orient.core.index.OIndexes.getFactories(OIndexes.java:76)
at com.orientechnologies.orient.core.index.OIndexes.getAllFactories(OIndexes.java:87)
at com.orientechnologies.orient.core.index.OIndexes.createIndex(OIndexes.java:117)
at com.orientechnologies.orient.core.index.OIndexManagerShared.createIndex(OIndexManagerShared.java:76)
at com.orientechnologies.orient.core.index.OIndexManagerProxy.createIndex(OIndexManagerProxy.java:68)
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.createIndex(OClassImpl.java:1123)
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.createIndex(OClassImpl.java:1085)
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.createIndex(OClassImpl.java:1081)
Does anybody know the solution for this. I also tryied closing and opening db, save schema before and using different indextypes but without any positive results.
Second Question: Is it necessary to define schema to index columns/attributes in the collection or is there another way?