I've tried to make simple web app integrated with Drools rule engine and deployed it on heroku. In controller action I'm executing method which imports and parses DRL file, and returns result. I've noticed weird behaviour. When I start app by command play run Drools don't want to work (I get some rule import errors and parse knowledge exception), but when I launch my app through Eclipse everything is working.
I've checked what exactly is executed through these different ways:
Eclipse executes: http://pastebin.com/RK7mnQ81
play run executes: http://pastebin.com/UH1rD7pb
I've tried to run play run with extra Java arguments existing in Eclipse execution, but I haven't found working combination.
Any ideas what arguments add to command play run to find working solution?
Thanks in advance for any help.
Stacktrace:
java.lang.IllegalArgumentException:
at drools.RuleEngine.readKnowledgeBase(RuleEngine.java:66)
at drools.RuleEngine.run(RuleEngine.java:28)
at controllers.Application.index(Application.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:546)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:500)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:476)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:471)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:159)
at play.server.PlayHandler$NettyInvocation.execute(PlayHandler.java:220)
at play.Invoker$Invocation.run(Invoker.java:265)
at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:200)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:165)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
Ok, I found a solution for me here: https://stackoverflow.com/a/7083303/894060
I've packed Drools-related classes and rule file in one jar file and I put that jar in one directory included in classpath -- it solved the problem.
I have no idea how to make a workaround/hack to get it worked.
I did the following to resolve the problem.I have added the following line to the file play\framework\pym\play\application.py in the method def getClasspath(self):
classpath.append(os.path.normpath(os.path.join(os.path.join(self.path, 'tmp'),'classes')))
The above just adds the classes which are their in the play tmp > classes directory to the classpath.
Everything works fine.
But i really didn't understand how play is able to resolve these references where as Drools is failing to do so.
Related
I'm trying to use Nd4j in a Kotlin project in Intellij IDEA. In Project Structure -> Libraries, I used the "From Maven" command to add the following libraries.
org.deeplearning4j:deeplearning4j-core:1.0.0-beta
org.nd4j:nd4j-native-platform:1.0.0-beta
org.datavec:datavec-api:1.0.0-beta
With those libraries I can compile my project, but when I run it fails with an exception.
Caused by: java.lang.RuntimeException: ND4J is probably missing dependencies. For more information, please refer to: http://nd4j.org/getstarted.html
at org.nd4j.nativeblas.NativeOpsHolder.<init>(NativeOpsHolder.java:51)
at org.nd4j.nativeblas.NativeOpsHolder.<clinit>(NativeOpsHolder.java:19)
... 10 more
Caused by: java.lang.UnsatisfiedLinkError: no jnind4jcpu in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1220)
at org.bytedeco.javacpp.Loader.load(Loader.java:980)
at org.bytedeco.javacpp.Loader.load(Loader.java:879)
at org.nd4j.nativeblas.Nd4jCpu.<clinit>(Nd4jCpu.java:10)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.bytedeco.javacpp.Loader.load(Loader.java:938)
at org.bytedeco.javacpp.Loader.load(Loader.java:879)
at org.nd4j.nativeblas.Nd4jCpu$NativeOps.<clinit>(Nd4jCpu.java:1310)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.nd4j.nativeblas.NativeOpsHolder.<init>(NativeOpsHolder.java:29)
... 11 more
Caused by: java.lang.UnsatisfiedLinkError: no nd4jcpu in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1220)
at org.bytedeco.javacpp.Loader.load(Loader.java:965)
... 21 more
Looking through the project folder I see that IDEA has downloaded lots of jar files for nd4j-native-platform, but there's no sign of any JNI libraries. What else do I have to do?
Intellij's "From Maven" feature doesn't support the classifiers that JavaCPP and ND4J (and other libraries that use native code) use. Maven will work great but if you really can't use it for some reason, you can manually add the nd4j-native-1.0.0-beta2-macosx-x86_64.jar file and openblas-0.3.0-1.4.2-macosx-x86_64.jar file. That should be enough to run simple things, but you'll have to manually do that for every other native dependency as you use more and more stuff (like OpenCV). That's why Maven is recommended.
If you include those 3 dependencies, there are zero reasons why it should fail unless you're on an unsupported OS for some reason.
We support everything from android to IBM power so that is unlikely though.
I'm also confused by what you mean about not seeing any JNI libraries. Those are all in the jar files. We use javacpp (which we also maintain) to manage those things.
You will find those libraries under ~/.javacpp/cache - you should not have any reason to touch those though.
Could you clarify what you are looking for there?
Beyond that, there is nothing else you have to do. I'm assuming something just didn't load correctly.
Our standalone pom works out of the box: https://github.com/deeplearning4j/dl4j-examples/blob/master/standalone-sample-project/pom.xml - maybe double check this, that or reload. I can only assume you created the project wrong somehow. File -> New Maven project should be all you need to do.
When running a jar file that i created from a maven project as such:
java -jar basictool.jar
I get this error exception:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.util.MissingResourceException: Can't find bundle for base name com/kit/version, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(UnknownSource)
at java.util.ResourceBundle.getBundleImpl(Unknown Source)
at java.util.ResourceBundle.getBundle(Unknown Source)
at com.factories.FactoryImpl.<init>(FactoryImpl.java:80)
at com.parsers.BasicParser.<init>(BasicParser.java:32)
at com.parsers.FileParser.<init>(FileParser.java:76)
at com.tools.BasicTool.main(BasicTool.java:75)
... 5 more
I created the jar file by using the maven jar creation wizard:
Right-click on project, select Export > Java > Runnable JAR file with options
Launch configuration: BasicTool - work
Export destination: C:\Users\Victor\Documents\basictool.jar
Library handling: Package required libraries into generated JAR
The version.properties file is kept inside of the src/main/resources, as com/kit/version.properties.
I have checked that the version.properties file is found inside of the jar file by running:
jar tf basictool.jar > output.txt
where i find the version.properties file as such:
resources/com/kit/version.properties
I attempt to load the resource like this:
ResourceBundle.getBundle("com/kit/version");
My machine and environment specifications are as followed:
Windows 7, Spring version: 3.7.2.
Note:
I found many questions similar to the one i have, but the answers i have found point to the properties file being properly named or placed in the correct location. From those answers i learned that version.properties is fine, since ResourceBundle.getBundle("com/kit/version") will first look for version.class then version.properties by default. It will also look for version_en_US.properties before ultimately looking for the base name version.properties.
I seem to be in line with the above, since the file version.properties is in the correct location and named correctly. I also seem to be in line with what other answers have offered :(
I would also like to point out that it finds the resource just fine when i run the program from spring, which brings me to suspect that something about the jar's creation process is the cause of the problem.
And it is also important to note that the properties file is in another maven project.
I hope i offered enough/clear details. Any help would be appreciated, thank you in advance!
If your application calls ResourceBundle.getBundle("com/kit/version"); from with in Eclipse everything works fine.
But when you create a jar file in the way you described (export -> java -> runnable jar), the version.properties is placed within the jar file at resources/com/kit/version.properties. Mind the "resources" in front of the path.
If you call this jar with java -jar basictool.jar outside Eclipse the version.properties cannot be found and java.util.MissingResourceExceptionis thrown.
If you change the path and call ResourceBundle.getBundle("resources/com/kit/version"); it won't work within Eclipse but java -jar basictool.jar will do.
It seems exporting the project from Eclipse causes the problem.
I would suggest to create the jar file to use without Eclipse with the maven-assembly-plugin.
An example can be found here.
This plugin creates a jar file without the resources directory and so the call of ResourceBundle.getBundle("com/kit/version"); works within and outside of Eclipse.
When I run ./gradlew I get
Exception in thread "main" java.lang.NoClassDefFoundError:
org/gradle/wrapper/GradleWrapperMain Caused by:
java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain
at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:190) at
java.lang.ClassLoader.loadClass(ClassLoader.java:306) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at
java.lang.ClassLoader.loadClass(ClassLoader.java:247)
My project compiles using the Android Studio but stopped compiling from command line
Probably something went bad. The solution:
Install gradle: brew install gradle
Regenerate wrapper: gradle wrapper
See https://github.com/drone/drone/issues/256
My .gitignore had *.jar in it, so I wasn't getting all the jars I needed in my repository.
I had the same, or similar, problem when trying to build my app from command line, but with an exception thrown for 'java.lang.ClassNotFoundException: com.sun.tools.javac.util.Context' which did not happen when building within Android Studio. I found out that AS brings along it's own JRE and I resolved the issue by setting 'JAVA_HOME' to the AS JRE path. In my case it turned into:
$ JAVA_HOME=/opt/android-studio/jre ./gradlew build
You can find this path under 'File' -> 'Project Structure' -> 'SDK Location', see screenshot.
I hit this issue when I have a directory with a ":" (no quotes, just a colon) in it.
This was on a linux machine.
Before:
"my:directory"
as in
/Users/me/projects/project1/my:directory/
then i renamed it to
/Users/me/projects/project1/my_directory/
and the error went away.
Following instructions at http://wiki.hl7.org/index.php?title=FHIR_Build_Process my FHIR build is failing. I modified the publish.bat to ensure it uses the correct JDK. Running it on Windows 7 64-bit machine with JDK 1.6 (also tried JDK 1.7) and both failing with same error.
Looks like some Saxon JAR hell somewhere. Any ideas?
...validate v2-tables 441sec 755MB
...validate v3-codesystems 443sec 889MB
Reference Platform Validation. 447sec 1067MB
...test adversereaction-example 447sec 1067MB
Exception in thread "main" java.lang.NoSuchMethodError: net.sf.saxon.Configuration.newConfiguration()Lnet/sf/saxon/Configuration
;
at net.sf.saxon.xpath.XPathFactoryImpl.<init>(XPathFactoryImpl.java:33)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at javax.xml.xpath.XPathFactoryFinder.loadFromService(XPathFactoryFinder.java:401)
at javax.xml.xpath.XPathFactoryFinder._newFactory(XPathFactoryFinder.java:222)
at javax.xml.xpath.XPathFactoryFinder.newFactory(XPathFactoryFinder.java:143)
at javax.xml.xpath.XPathFactory.newInstance(XPathFactory.java:185)
at javax.xml.xpath.XPathFactory.newInstance(XPathFactory.java:99)
at org.hl7.fhir.tools.publisher.Publisher.testSearchParameters(Publisher.java:2796)
at org.hl7.fhir.tools.publisher.Publisher.testSearchParameters(Publisher.java:2785)
at org.hl7.fhir.tools.publisher.Publisher.validateRoundTrip(Publisher.java:2759)
at org.hl7.fhir.tools.publisher.Publisher.validateXml(Publisher.java:2656)
at org.hl7.fhir.tools.publisher.Publisher.execute(Publisher.java:378)
at org.hl7.fhir.tools.publisher.Publisher.main(Publisher.java:281)
A workaround... do a fresh build of the publisher tool jar from source.
Following instructions in the build/buildhowto.txt I was able to build the tool jar inside Eclipse, run the Publisher successfully from inside Eclipse and then export it as a fresh tool jar overwriting the one I pulled from SVN. The freshly build one then ran to completion from the command line.
Could be there's just a problem with the version of tools jar out there in SVN at the moment.
For the record I am working with Version 0.12-1953.
You have two classes net.sf.saxon.Configuration in your classpath. One containing the method newConfiguration() and one not.
The method is probably called from Saxon-HE 9.x, and the class net.sf.saxon.Configuration is found in saxon 8.x, while the class should have been found inside Saxon-HE 9.x, where it also is, and does have this method.
So, check your dependencies to see if saxon 8.x is called, and try replacing that with Saxon-HE 9.x, then your problem is solved
I've downloaded Kyoto Tycoon via:
hxxps://bitbucket.org/EP/kyototycoon-java
When running mvn install I get plenty of warnings telling me it couldn't find several files:
http://pastebin.com/znpJ3d5n
When I first started running the install I was getting a lot of failures and no errors. After blindly going around and trying to install things separately, the output now looks like this. I have no experience with Maven so editing the pom.xml file is out of the question. I've tried using the ignore tests and compiling, and I get few jar files. This allows me to compile "Example.java" using:
javac -cp .:target/kyototycoon-0.2-SNAPSHOT.jar Example.java
I then try to run the code using:
java -cp .:target/kyototycoon-0.2-SNAPSHOT.jar Example
but I get an runtime error:
Exception in thread "main" java.lang.NoClassDefFoundError: Exception in thread "main" java.lang.NoClassDefFoundError: com/twitter/finagle/Codec
at kyototycoon.SimpleKyotoTycoonClient.<init>(SimpleKyotoTycoonClient.java:16)
at Example.main(Example.java:11)
Caused by: java.lang.ClassNotFoundException: com.twitter.finagle.Codec
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 2 more
I'm assuming this all comes back the the maven install failing, but I'm not sure how to fix it.
Any direction is appreciated. There doesn't seem to be a large support group for Kyoto.
For anyone experiencing this same issue, I found that JAR files I needed were being created. They were being stored in ~/.m2/repository/kyototycoon/kytotycoon/. I created a disgusting looking classpath that included all of these JAR files and this allowed me to compile AND run the Example.java file.
If "editing the pom file is out of the question" I'd strongly recommend steering clear of Maven.
In any case, you can install local jars to your repository if the artifact isn't available from any repository.