I have developed a linux shared library to communicate with pos terminals. The library has been developed using C language, and the routines are imported in to a java program using JNI interface. I have tested the library with the simple Java class it works perfectly.how ever when I try to develop a front end java application using netbeans it pops up Unsatisfied link error . so i recompiled the library with the package name embedded in ever function call with in the shared library and the issue was resolved. I found the package name causes the specific error. Is there a way to come out from this problem. because I cant ask the client to keep the package name static. it should be able to change as they need. I tried several compiler and linker directive but failed ..The current working library has been compiled using the following command
gcc -shared -o libecr.so -fpic ecr.c -lusb-1.0
This compiles with no errors in Fedora 14.
libecr.so is my shared library
ecr.c is the source code file
lusb is the libusb which is referenced by ecr code
Related
I need to create an original .so library (C code) that uses another .so library. After creating my .so library I wrote a short test program code on C that invokes functions of my lib. It works, but when I compile this program I use that command:
gcc my_test.c -lm -o my_test_program -lmy_lib -lother_lib -L
I need to use my library in Java code (JNA) but when I try to invoke functions from my lib I get this error:
/usr/lib64/libmy_lib.so.0: undefined symbol
I think that means it has lost dependence of other_lib.
What can I do to add dependence in my_lib? Or other solutions?
I would like to use jython for basic web scraping task rather than learning java. To learn the basics I'm using an example from http://blog.databigbang.com/web-scraping-ajax-and-javascript-sites/ I've been unsuccessfully trying to run the gartner.py code from Windows cmd. Could anyone suggest a resolution to why both
jython -J-classpath "path\to\the\jars\*" path\to\gartner.py
and
jython path\to\gartner.py
keep on throwing out
Traceback (most recent call last):
File "path\to\gartner.py", line 1, in <module>
import com.gargoylesoftware.htmlunit.WebClient as WebClient
ImportError: No module named gargoylesoftware
given I've got environment variables set up for jython path\to\jython\bin, for java path\to\Java\jdk-14.0.1\bin and for the htmlunit-2.40.0 I've added path\to\jars\htmlunit-2.40.0\lib to the CLASSPATH.
I understand that jython should pick up the specified package in jython -J-classpath "path\to\the\jars\*" path\to\gartner.py but it does not find it. Also, I understand that in the case of jython path\to\gartner.py the defined CLASSPATH variable is available to Java pointing at htmlunit-2.40.0 (as mentioned above) whilst jython serves only as a translator from python to java. So - in my understanding - java shouild have all parameters available to import the desired module. Please, could anyone confirm?
I appreciate this subject has been somewhat discussed but there is no clear resolution available. What could I be missing?
The error looks very clearly like you're missing a Java dependency. The jython issue with this specific library has already been discussed in a different thread: instantiating a webclient object in jython giving strange results
I wish to make a java implementation based on a C++ library using the JNI. Unfortunately, when I wish to use the shared library in java it can not be found. The problem with this shared library is that it links another shared library. I have two different cases one works (but shouldn't be used) and the other one doesn't.
The Ana lib must always be static. The Clara lib must always be shared. It works when the Bob lib is static, but it should be shared and it should include Ana and Clara.
Case 1 (Works and can be loaded in the correct java.library.path).
sharedlibJava.so links: staticlibAna.a staticlibBob.a sharedlibClara.so
Case 2 (Doesn't work because it can't be loaded even though the java.library.path is correct).
sharedlibBob.so links: staticlibAna.a and sharedlibClara.so (the basic c++ implementation is tested and it works without problems)
sharedlibJava.so links: sharedlibBob.so (the java implementation should be available using this new shared library).
The problem is that when I try to load the library it doesn't even find it in the correct java.library.path even though it is located there.
I would really appreciate any feedback regarding this issue.
Put all your path locations on LD_LIBRARY_PATH. Alternatively, put them into -Djava.library.path
If you have compiled code properly, I don't think you should experience issues while accessing shared library.
If you compile one code as shared lib, and then refer to it by linking other code with shared lib, it should work just fine
cc -g -shared -fpic c/recipeNo023_AnotherFunction.c -o lib/libAnotherFunction.$(EXT)
cc -g -shared -fpic -I${JAVA_HOME}/include -I${JAVA_HOME}/include/$(ARCH) c/recipeNo023_HelloWorld.c -L./lib -lAnotherFunction -o lib/libHelloWorld.$(EXT)
Then, you should be able to call the code by passing lib location inside -Djava.library.path
java -Djava.library.path=:./lib -cp target recipeNo023.HelloWorld
library: :./lib
Hello world!
Hello from another function!
For the full sample code, take a look here:
https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo023
I am trying to convert a proprietary, third party IDL into java. I downloaded the IDL, opened up cmd.exe, navigated to the directory containing the IDL files, and then typed in the following command which was given explicitly by the provider of the third party IDL:
java com.sun.tools.corba.se.idl.toJavaPortable.Compile -fallTIE -pkgPrefix types org.hl7 -pkgPrefix CTSMAPI org.hl7 -pkgPrefix CTSVAPI org.hl7 CTSVAPI.idl
Unfortunately, this is throwing the following error in the command line:
Error: could not find or load main class com.sun.tools.corba.se.idl.toJavaPortable.Compile
I googled and found the definition of the class at this link.
I typed in java in the command prompt and got a list of methods, indicating that I can call java from the command prompt in that directory. Other web sites indicate that com.sun.tools.corba.se.idl.toJavaPortable.Compile has been a part of the jdk since at least version 1.3. So why am I getting this error?
The provider doesn't know what he's talking about. You should use the 'idlj' tool, with the same or corresponding arguments, not this undocumented invocation.
You may be getting the error because you're running the JRE 'java', not the JDK one. But it's wrong wrong wrong. Use idlj.
I have developed an Matlab code for stegnography which requires some preprocessing to be done by a Java file.
The java file aes1.java contains the function encrypt(String s) which needs to be called by matlab code:
javaaddpath('C:\Users\Aneesh\Desktop\BE_Project');
disp(char(javaMethod('hash', 'aes1', userText)));
I am getting the following error:
Error using javaMethod
No class aes1 can be located on the Java class path
Error in project_mod (line 11)
disp(char(javaMethod('hash','aes1',userText)));"
Versions I'm using:
Matlab 2013a
Java 1.6
Any help would be greatly appreciated!
Update:
I have a .jar file which contains all the classes i need. I've imported it and tried using it but I'm still getting the same error!
Please take a look at the documentation. javaaddpath adds one or more folders of java Archive (jar) files.
You need to compile your java file to a class-file and add it using javaclasspath