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".
Related
I am trying to get used to python+java interaction and so I wrote a little python-script that I wanted to execute that script from my Spring Boot Application. That script is located in the (relative from the .java-file) path /scripts_py/getStockPrice.py that contains the getStockPrice-method (see code below). So I integrated jython and tried to execute the following CronJob:
#Component
public class CronService {
private PythonScriptSingleton pss = PythonScriptSingleton.getInstance();
private final Logger logger = LoggerFactory.getLogger(CronService.class);
//call every 5 sec
#Scheduled(fixedRate = 5000)
public void initStockPriceAPICall() {
this.getStockPrice("NFLX");
}
public void getStockPrice(String ticker) {
String result = (String) (Object) this.pss.getFunc_getPriceForTicker().__call__(new PyString(ticker));
try {
logger.info("Price is " + result);
} catch (NullPointerException e) {
logger.info("Catched NPE");
}
}
}
The PythongScriptSingleton (the idea was, that I probably need to execute that script a lot of times - so I tried to go for a singleton instance of this class that holds the script so I do not need to recompile it every time:
public class PythonScriptSingleton {
private static PythonScriptSingleton ps;
public static PythonScriptSingleton getInstance() {
if (ps == null) {
ps = new PythonScriptSingleton();
ps.initScript();
}
return ps;
}
private PyObject func_getPriceForTicker;
private PythonScriptSingleton() {
}
private void initScript() {
PythonInterpreter interpreter = new PythonInterpreter();
String fileUrlPath = "/scripts_py";
String scriptName = "getStockPrice.py";
interpreter.exec("import sys\n" + "import os \n" + "sys.path.append('" + fileUrlPath + "')\n" + "from "
+ scriptName + " import * \n");
String funcName = "getStockPrice";
PyObject someFunc = interpreter.get(funcName);
this.func_getPriceForTicker = someFunc;
interpreter.close();
}
public PyObject getFunc_getPriceForTicker() {
return func_getPriceForTicker;
}
}
The Python Script:
from yahoo_fin import stock_info as si
def getStockPrice(ticker):
price = si.get_live_price(ticker)
return price
I am using the embedded tomcat with Spring Boot (executable JAR-File) and jython-standalone 2.7.2:
<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7.2</version>
</dependency>
The error i keep running into says, that the script is not defined - I tried defining it with and without the file ending (.py), both did not change anything:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.fr.stockticker.pythoninteraction.CronService]: Constructor threw exception; nested exception is Traceback (most recent call last):
File "<string>", line 4, in <module>
ImportError: No module named getStockPrice
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:217) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1312) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
... 81 common frames omitted
Caused by: org.python.core.PyException: ImportError: No module named getStockPrice
at org.python.core.Py.ImportError(Py.java:329) ~[jython-standalone-2.7.2.jar:2.7.2]
at org.python.core.imp.import_first(imp.java:1230) ~[jython-standalone-2.7.2.jar:2.7.2]
at org.python.core.imp.import_module_level(imp.java:1361) ~[jython-standalone-2.7.2.jar:2.7.2]
at org.python.core.imp.importName(imp.java:1528) ~[jython-standalone-2.7.2.jar:2.7.2]
at org.python.core.ImportFunction.__call__(__builtin__.java:1285) ~[jython-standalone-2.7.2.jar:2.7.2]
at org.python.core.PyObject.__call__(PyObject.java:433) ~[jython-standalone-2.7.2.jar:2.7.2]
at org.python.core.__builtin__.__import__(__builtin__.java:1232) ~[jython-standalone-2.7.2.jar:2.7.2]
at org.python.core.imp.importAll(imp.java:1647) ~[jython-standalone-2.7.2.jar:2.7.2]
at org.python.pycode._pyx0.f$0(<string>:4) ~[na:na]
at org.python.pycode._pyx0.call_function(<string>) ~[na:na]
at org.python.core.PyTableCode.call(PyTableCode.java:173) ~[jython-standalone-2.7.2.jar:2.7.2]
at org.python.core.PyCode.call(PyCode.java:18) ~[jython-standalone-2.7.2.jar:2.7.2]
at org.python.core.Py.runCode(Py.java:1687) ~[jython-standalone-2.7.2.jar:2.7.2]
at org.python.core.Py.exec(Py.java:1731) ~[jython-standalone-2.7.2.jar:2.7.2]
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:268) ~[jython-standalone-2.7.2.jar:2.7.2]
at de.fr.stockticker.pythoninteraction.PythonScriptSingleton.initScript(PythonScriptSingleton.java:28) ~[classes/:na]
at de.fr.stockticker.pythoninteraction.PythonScriptSingleton.getInstance(PythonScriptSingleton.java:13) ~[classes/:na]
at de.fr.stockticker.pythoninteraction.CronService.<init>(CronService.java:12) ~[classes/:na]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_251]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_251]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_251]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_251]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:204) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
... 83 common frames omitted
I was able to run your program partially using Jython - I couldn't get the stock process from yahoo which is internally depends on numpy and looks like Jython doesn't support numpy as it being cpython library.
private void initScript() {
PythonInterpreter interpreter = new PythonInterpreter();
String fileUrlPath = "/users/sagar/demo/src/main/resources/python";
interpreter.exec("import sys");
interpreter.exec("sys.path.append('" + fileUrlPath + "')");
interpreter.exec("from getStockPrice import *"); this.func_getPriceForTicker =
interpreter.get("getStockPrice", PyFunction.class);
interpreter.close();
}
You will be able to get past your error but you will see error
Missing required dependencies ['numpy']
So I tried using another java python library jep and made changes as follow
#SpringBootApplication
#EnableScheduling
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
private final Logger logger = LoggerFactory.getLogger(DemoApplication.class);
//call every 5 sec
#Scheduled(fixedRate = 5000)
public void initStockPriceAPICall() throws JepException {
this.getStockPrice("NFLX");
}
private void getStockPrice(String ticker) throws JepException {
try (Interpreter interp = new SharedInterpreter()) {
String fileUrlPath = "/users/sagar/demo/src/main/resources/python";
interp.exec("import sys");
interp.exec("sys.path.append('" + fileUrlPath + "')");
interp.exec("from getStockPrice import *");
interp.set("ticker", ticker);
interp.exec("price = getStockPrice(ticker)");
Object result = interp.getValue("price");
logger.info("Price is " + result);
}
}
}
pom.xml
<dependency>
<groupId>black.ninia</groupId>
<artifactId>jep</artifactId>
<version>3.9.0</version>
</dependency>
Make sure to install jep module - it has native library
pip install jeb
Add java library path to load native library
-Djava.library.path=/usr/local/lib/python2.7/site-packages/jep
Reference - https://github.com/ninia/jep/wiki/Getting-Started
In my Spring Boot 1.5 application I use ClassPathResource to read a static file the application JAR:
// ...
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
#Slf4j
#Service
public class MyService {
private Resource resource = new ClassPathResource("a.txt");
private List<String> myStrings;
public MyService() {
myStrings = load(resource);
}
private List<String> load(Resource resource) {
try(Stream<String> stream = Files.lines(Paths.get(resource.getURI()))) {
myStrings = stream.filter(/* my filter */)
.collect(Collectors.toList());
} catch (IOException x) {
log.error("Failed to read '{}'.", resource.getFilename());
}
}
}
but this fails with:
Caused by: java.nio.file.FileSystemNotFoundException: null
at com.sun.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:171) ~[zipfs.jar:1.8.0_121]
at com.sun.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:157) ~[zipfs.jar:1.8.0_121]
at java.nio.file.Paths.get(Paths.java:143) ~[na:1.8.0_121]
at MyService.load(MyService.java:53) ~[classes!/:2.0.0-SNAPSHOT]
//...
How can I read a ClassPathResource embedded in my application JAR?
The JDK's Paths.get cannot resolve resources within JAR files so replace:
Files.lines(Paths.get(resource.getURI()))
with:
new BufferedReader(new InputStreamReader(resource.getInputStream())).lines();
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
this my project strucuture:
and i found the next exception:
aused by: org.springframework.webflow.engine.model.builder.FlowModelBuilderException: Couldtion at class path resource [WEB-INF/flow/consultaDeutes/consultaDeutes.xml]
at org.springframework.webflow.engine.model.builder.xml.XmlFlowModelBuilder.init(Xml at org.springframework.webflow.engine.model.builder.DefaultFlowModelHolder.assembleF.java:86)
at org.springframework.webflow.engine.model.builder.DefaultFlowModelHolder.getFlowMo:61)
at org.springframework.webflow.engine.builder.model.FlowModelFlowBuilder.doInit(Flow ... 47 more
Caused by: java.io.FileNotFoundException: class path resource [src/main/webapp/WEB-INF/flow/consultaDeutes/consultaDeutes.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.ja at org.springframework.webflow.engine.model.builder.xml.DefaultDocumentLoader.loadDova:98)
at org.springframework.webflow.engine.model.builder.xml.XmlFlowModelBuilder.init(Xml ... 50 more
What is wrong here? i'm pretty desperate ty.
#Override
protected FlowDefinitionResource getResource(FlowDefinitionResourceFactory resourceFactory) {
FlowDefinitionResource resource = resourceFactory.createResource("consultaDeutes.xml");
Assert.assertNotNull(resource);
return resource;
}
/*[src/main/webapp/WEB-INF/flow/consultaDeutes/consultaDeutes.xml]*/
#Test
public void testFlowShouldEnterStartState()
{
this.startFlow(context);
// assertCurrentStateEquals("a_cargar_info");
}
I have a code below. I can compile and run it normally in NetBeans. But with javac/java, I cannot run it normally. What do I miss?
The code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/* the original code is from link: http://edu.qudong.com/safe/base/Javascript/shilidaima/20080514/12527.html */
package gendemo;
/**
*
* #author tomxue
*/
class Gen2 {
private Object ob; //定义一个通用类型成员
public Gen2(Object ob) {
this.ob = ob;
}
public Object getOb() {
return ob;
}
public void setOb(Object ob) {
this.ob = ob;
}
public void showTyep() {
System.out.println("T的实际类型是: " + ob.getClass().getName());
}
}
public class GenDemo2 {
public static void main(String[] args) {
//定义类Gen2的一个Integer版本
Gen2 intOb = new Gen2(new Integer(88));
intOb.showTyep();
int i = (Integer) intOb.getOb();
System.out.println("value= " + i);
System.out.println("----------------------------------");
//定义类Gen2的一个String版本
Gen2 strOb = new Gen2("Hello Gen!");
strOb.showTyep();
String s = (String) strOb.getOb();
System.out.println("value= " + s);
}
}
By javac, after compiling, I got below result.
tomxue#ubuntu:~/test$ javac GenDemo2.java
tomxue#ubuntu:~/test$ ls
Gen2.class GenDemo2.class GenDemo2.java
And then, if I run it like this:
tomxue#ubuntu:~/test$ java Gen2
Exception in thread "main" java.lang.NoClassDefFoundError: Gen2
Caused by: java.lang.ClassNotFoundException: Gen2
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
tomxue#ubuntu:~/test$ java GenDemo2
Exception in thread "main" java.lang.NoClassDefFoundError: GenDemo2
Caused by: java.lang.ClassNotFoundException: GenDemo2
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
What is wrong with it?
The problem is that java expects the directory structure to match the package name ("gendemo"), so it can't find your classes. move your java file into a sub-directory named gendemo, then compile it from the top directory using javac gendemo/GenDemo2.java and run it using java -cp . gendemo.GenDemo2.
When you run java SomeClass JVM load SomeClass and trying to run SomeClass.main method.
So you should run:
java GenDemo2
or add:
public static void main(String[] args) to Gen2.java