I've set up a jep project within IntelliJ-IDEA, and keep getting this error when I run my code:
Exception in thread "main" jep.JepException: <class 'ModuleNotFoundError'>: No module named 'spacy'
at src/main/python\nlq_wrapper.<module>(nlq_wrapper.py:2)
at <string>.<module>(<string>:1)
at jep.Jep.exec(Native Method)
at jep.Jep.exec(Jep.java:478)
at com.siemens.nlqwrapper.NLQWrapper.load(NLQWrapper.java:37)
at com.siemens.nlqwrapper.Main.main(Main.java:9)
Even though spacy is included in my interpreter SDK packages.
Another weird thing is that the Python terminal within IntelliJ-IDEA can find and use spacy.
But when I try and run the program from the terminal or from my system's CLI, it can't find the modules and I get the same error.
Is there some extra configuration for jep that I need to do to be able to use other python modules with it? or is jep just not compatible with other modules?
EDIT
For further clarification here are the run configurations for Java and Python.
Java run configuration:
Python run configuration:
I fixed it thru this code you call before JEP interpreter:
PyConfig pyConfig = new PyConfig();
pyConfig.setPythonHome("/home/user/[NEW_PYTHON_HOME]/");
try {
MainInterpreter.setInitParams(pyConfig);
} catch (JepException e) {
e.printStackTrace();
}
Ali
Related
I use JNA to load a c++ library (.so) in a java project. I package my library inside the jar, and load it from the jar when instantiating the java class that uses it. I do all this like so:
mvn install compiles the c++ code and packages the outcome dynamic library inside the jar.
I call in a static context when instantiating the LibraryWrapperClass the following
System.load( temp.getAbsolutePath() );
where temp is a temporary file containing the library which was found in the jar. This code is based on the work found here adamheinrich
- I call Native.loadLibrary(LIBRARYPATH) to wrap the library into a java class.
private interface Wrapper extends Library {
Wrapper INSTANCE = Native.loadLibrary( C_LIBRARY_PATH, Wrapper.class );
Pointer Constructor();
...
}
I run tests and validate that the library was found and up and running.
I use a java web project that depends on this project. It uses tomcat and runs fine in local.
My issue is that when I deploy on the server, the LibraryWrapperClass cannot instantiate. Error on server is:
java.lang.NoClassDefFoundError: Could not initialize class pacakgeName.LibraryWrapperClass
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at org.hibernate.annotations.common.util.StandardClassLoaderDelegateImpl.classForName(StandardClassLoaderDelegateImpl.java:57)
at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl$4.classForName(MetadataBuilderImpl.java:758)
at org.hibernate.annotations.common.reflection.java.JavaReflectionManager.classForName(JavaReflectionManager.java:144)
at...
This error seems that the library is found, since there is not the UnsatisfiedLinkError exception thrown. But something else is failing. Do someone know what could happen? How could I debug?
I recall that everything works perfectly in local.
How could I debug?
1. with strace
strace will give you what files Tomcat is trying to open : strace -f -e trace=file -o log.txt bin/startup.sh
After this, look for packageName in log.txt, or other files not found with :
egrep ' open.*No such file' log.txt
2. with JConsole
Enable JMX, launch a JConsole, go to VM summary tab, and check/compare very carefully VM arguments/classpath/library path/boot class path
3. dependency listing with ldd
If a dependency issue is likely to be the problem, the ldd sharedLibraryFile.so command lists all the dependencies and allows to track which one might be missing.
I already install jco3 for linux.
I'm using ubuntu 16.04 x86_64 and java-8-oracle
as the documentation said, i need to add LD_LIBRARY_PATH and CLASSPATH to jco directory.
export LD_LIBRARY_PATH=/home/zain/sapjco
export CLASSPATH=/home/zain/sapjco/sapjco3.jar
then create simple jco connection test
import com.sap.conn.jco.*;
public class testjco {
public static void main(String[] args) {
JCO.Client mConnection;
try {
mConnection = JCO.createClient("301", // SAP client
"somecoolguy", // userid
"****", // password
"EN", // language
"XXX", // application server host name
"00"); // system number
mConnection.connect();
System.out.println(mConnection.getAttributes());
mConnection.disconnect();
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
}
}
but when i run my project i got error
error: package com.sap.conn.jco does not exist
is there any particular step i missed?
I don't know if you've already done this but:
export LD_LIBRARY_PATH=/home/zain/sapjco
export CLASSPATH=/home/zain/sapjco/sapjco3.jar
only work in the current bash instance, which means that if you ever close that terminal window then that export path will be gone. One way to keep it is to add it to your ~/.profile
then you can just run this source ~/.bashrc in order to refresh your bash window.
Don't know if that helped since I have never coded Java in Ubuntu, only on Mac with Eclipse/Idea. Anyways, if that's not how to do it, then there's a problem with the way you imported your sapjco3.jar to your project.
You also need to use your CLASSPATH environment variable and pass it as classpath argument to your JVM instance that shall run your project.
But I don't think that you are really at the step of running your project, you must be already failing to compile your class testjco. (By the way, I recommend to follow the common Java naming conventions and let all class names start with an uppercase letter.)
You are importing the package com.sap.conn.jco which belongs to the SAP Java Connector 3.0 (sapjco3.jar), but in your code you use the JCo API from package com.sap.mw.jco of the outdated SAP Java Connector 2.0/2.1 (sapjco.jar). That does not work and cannot be compiled.
So, here's my problem. I've got my ANTLR4 code successfully compiled, without errors and now I want to test it out. The ANTLR4 Documentation tells me, to test my applications, I shall do this:
java org.antlr.v4.runtime.misc.TestRig
I've tried this and got following error:
Error: Main Class org.antlr.v4.runtime.misc.TestRig couldn't be found or load.
I've checked if my CLASSPATH wasn't set, but everything was correctly set as it should be. I also tried moving the file directly to my test folder and opened CMD there and tried it again, I occur the same error. Searching in the Internet didn't help, as no one seemed to have occurred this error with ANTLR4 before.
Specs:
Java 1.7.0.55
ANTLR 4.4
There seems to be something wrong with your classpath, contrary to your belief everything is okay.
When I download the ANTLR 4 JAR and run TestRig:
wget http://www.antlr.org/download/antlr-4.4-complete.jar
...
java -cp antlr-4.4-complete.jar org.antlr.v4.runtime.misc.TestRig
I see the following on my console:
java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName
[-tokens] [-tree] [-gui] [-ps file.ps] [-encoding encodingname]
[-trace] [-diagnostics] [-SLL]
[input-filename(s)]
Use startRuleName='tokens' if GrammarName is a lexer grammar.
Omitting input-filename makes rig read from stdin.
I have create java application using sikuli-script(latest version 1.0.1).
I added the sikuli-script.jar to the Referenced Libraries (I configured using this answer Answer Link)
java code folder structure -->
Java code -->
package com.example.sikuli;
import org.sikuli.script.*;
import java.util.concurrent.TimeUnit;
public class TestSikuli {
public static void main(String[] args) {
Screen s = new Screen();
App app = new App("C:/Program Files/Mozilla Firefox/firefox.exe");//firefox path
try{
app.focus();
TimeUnit.SECONDS.sleep(2);
s.click("imgs/1391152193781.png", 0);//url bar image
s.type(null, "http://www.google.lk", 0);
s.click("imgs/1391152289812.png", 0);//click search image
}
catch(FindFailed e){
e.printStackTrace();
}
}
}
After that i set the the Run Configutrtion such as PATH and SIKULI_HOME
Next I run the code it's working properly.
Then I create .exe using launch4j and according to this site instructions --> How to Create an Executable File from Eclipse
After that i run the .exe file from command prompt then following errors occurred. Please help me.
Error -->
[error] ResourceLoaderBasic: check: libs dir is empty, has wrong content or is outdated
[action] ResourceLoaderBasic: check: Please wait! Trying to extract libs to: C:\Documents and Settings\Dell\SikuliX\libs
[error] ResourceLoaderBasic: loadLib: Fatal Error 109: not found: C:\Documents and Settings\Dell\SikuliX\libs\VisionProxy.dll
[error] Terminating SikuliX after a fatal error(109)! Sorry, but it makes no sense to continue!
If you do not have any idea about the error cause or solution, run againwith a Debug level of 3. You might paste the output to the Q&A board.
--1. when programming in Java using Sikuli, you should always use sikuli-java.jar (sikuli-ide.jar contains much stuff not needed here).
--2. Set a JVM option -Dsikuli.Debug=3 when running the exe to get more details about what's going on. I guess the problem is, that for some reason the export of the native libs does not work in the context of a launch4J exe (I did not test this yet).
--3. always use the latest version (1.1.1 in this case, still nightly but pre-final ;-) http://sikulix.com
I managed to successfully compile my code, but I'm not able to execute it. How do I fix this?
scannerTesting is my package and ScannerTesting.java is my main file.
D:\Java>javac Testing\src\scannerTesting\ScannerTesting.java
D:\Java>java Testing\src\scannerTesting\ScannerTesting
Exception in thread "main" java.lang.NoClassDefFoundError: Testing\src\scannerTesting\ScannerTesting <wrong name: scannerTesting/ScannerTesting>
.
.
.
java -cp ./Testing/src scannerTesting.ScannerTesting
When you run java, it looks for matching classes within its classpath. So what these arguments are doing is add your source folder to the classpath using -cp, and specify that the class that should be run is scannerTesting.ScannerTesting.
For more information, check out java cli tool documentation at Oracle
scannerTesting is your package name,right?
If so, I suggest you run command "java" under the workspace D:\Java\Testing\src
java scannerTesting.ScannerTest