Native library in Tomcat UnsatisfiedLinkError + Windows + eclipse - eclipse

This question might have been asked earlier on SO, and please be assured I did check all the available solutions. Was still unable to get it to run
My problem is exactly as described in this post Shared native library in Tomcat UnsatisfiedLinkError
Standalone Java application is running perfectly well. However with Tomcat(9) it fails to run and throws
java.lang.UnsatisfiedLinkError: third_party.org.chokkan.crfsuite.crfsuiteJNI.swig_module_init()V
at third_party.org.chokkan.crfsuite.crfsuiteJNI.swig_module_init(Native Method)
at third_party.org.chokkan.crfsuite.crfsuiteJNI.<clinit>(crfsuiteJNI.java:87)
at third_party.org.chokkan.crfsuite.Tagger.<init>(Tagger.java:39)
I know that my DLL is being loaded, also I checked that the folder my dll is in, is in the PATH variable. I have also checked the classes being loaded and the DLL is infact being loaded.
I have noticed 3 types of UnsatisfiedLinkError at SO
1) java.lang.UnsatisfiedLinkError: third_party.org.chokkan.crfsuite.crfsuiteJNI.swig_module_init()V
2) java.lang.UnsatisfiedLinkError: third_party.org.chokkan.crfsuite.crfsuiteJNI.swig_module_init()B
3) Where the class loader is loading twice.
I believe the V , at the end does signifies something. But I am not able to figure out exactly what?
One of the accepted answers in the SO post I shared above claims it has something to do with version. I do not understand how is that an acceptable solution since it works perfectly well when run as a standalone java application.
Wasted a lot of time already, any help is appreciable.
Thanks
Chahat

I faced with the same issue. I finally find the solution. It works for me.
First, I instaled libLBFGS and crfsuite. You can find the instruction here (http://www.chokkan.org/software/crfsuite/manual.html). The libcrfsuite.so will be install in /usr/local/lib
Second, I edit tomcat config in order to load native library. I create setenv.sh in tomcat bin folder, set CATALINA_OPTS variable with content :
export CATALINA_OPTS="-Djava.library.path=/usr/local/bin:/usr/local/lib"
Finally, I used custom ServletContextListener and explicitly load libcrfsuite.so by System.load(). I go this link to download lib (https://github.com/vinhkhuc/jcrfsuite/tree/master/src/main/resources/crfsuite-0.12)

I had a similar problem but not with Tomcat.
I ended up copying the logic from one of their classes and simply invoking:
static {
try {
CrfSuiteLoader.load();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

Related

How to set export Path in ubuntu server?

In ubuntu, I export library path while running my scala application to load the .so files. But the files are not loaded. So an exception occurs when I hit my methods. The exception I get is as follows enter image description here
I don't know how to fix this issue. Lib folder contains all those library files needed but still error appears. Particularly it shows libboost_filesystem cannot be loaded. please help me to fix this issue. Thanks for your help.
You need to make sure your libboost libraries are installed and available for the JVM. There are multiple ways to help JVM find those libraries like LD_LIBRARY_PATH or -Djava.library.path=. Check this article for examples: https://www.chilkatsoft.com/java-loadLibrary-Linux.asp.

Java Applet using jacob to load com dll method getting Errormessage : NoClassDefFoundError: com/jacob/activeX/ActiveXComponent

I need to create an Applet that can load a com method, for this purpose I used the java com bridge (jacob) deal with the com dll, and My Environment is set as follow:
os:win7x64
IDE:Eclipse32bit-version
COM DLL:BPIKeyCOM.dll 32-bit version
com bridge : jacob1.17-32bit version
server: Tomcatv7.0
I put jacob.dll under C:\Windows\System32 and jacob.jar under WEB-INF\lib
When I run the project, it's working fine in Eclipse. But when deployed on the web, the following error messages appear:
java.lang.NoClassDefFoundError: com/jacob/activeX/ActiveXComponent
at Fmain.Ikeycheck(Fmain.java:180)
at Fmain.init(Fmain.java:73)
at sun.applet.AppletPanel.run(AppletPanel.java:435)
at java.lang.Thread.run(Thread.java:724)
Caused by:
java.lang.ClassNotFoundException: com.jacob.activeX.ActiveXComponent
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:219)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:152)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)...
It looks like this message is talking about that it can't find com/jacob/activeX/ActiveXComponent.class, but I don't understand how.
I've already searched for many solutions and tried to solve it, but it still keeps showing this error message, I use to do sigh jar, make sure the classpath is correct, and even try to change the policy file...etc. But still, it's not working!
You've installed the dll and jacob.jar into your Java Web container; unfortunately, that is not the user's web browser (e.g. Applet Container). You need to add the dll and jacob.jar file into the applet jar. You should probably also read this. It's also important to point out that if your users install a 64-bit jdk, or aren't running Windows - then your Applet will not work.
Have a look at the example provided with jacob:
e.g.
jacob-1.17_src.zip\jacob-1.17\samples\com\jacob\samples\applet
This is a nice example how it works - it even has a readme.txt with a full description inside...

rJava error when running with Eclipse

I have installed R 3.0.1 and Eclipse Kepler. (I have installed StatE to run R-script through and Eclipse R-console with no problem.) However, I cannot seem to get a java program to run. I'm posting my issues to see if anyone else has encountered them or can help me understand what I'm doing wrong. After installing R, rJava (through R), and eclipse, I ran the RJavaEclipse Plugin from studytrials.com. Then I configured the paths to the appropriate libraries or .dll.
When I try to run the rtest.java file that comes with the rJava JRI, I get the following error:
Cannot find JRI native library!
Please make sure that the JRI native library is in a directory listed in java.library.path.
java.lang.UnsatisfiedLinkError: no jri in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.rosuda.JRI.Rengine.<clinit>(Rengine.java:19)
at rtest.main(rtest.java:61)
When I try to run via the run tab in eclipse -> run configurations -> R -> rtest, I get a pop-up warning that says:
R_HOME must be set or R properly installed (\Software\R-core\InstallPath registry entry must exist).
So, following the advice that so many on SO give, I tried to find the answer in the warning message.
I found the path information in Eclipse (and Windows) was pointing to the correct locations both in the library and in the R run configuration:
(C:\Users\csnyder\Documents\R\win-library\3.0\rJava\jri\x64;C:\Program Files\Java\jre7\bin\server;C:\Program Files\R\R-3.0.1\bin\x64)
These paths also match the windows environmental paths.
So, I'm at a loss. If anyone has any suggestions on what my issue might be, I would greatly appreciate it. Please comment if you require any additional information.
I had the exact same problem on Linux. In essence, this set up is not updating java.library.path properly and the linkage to the JRI jars fails. I started by printing the path to the console with:
System.out.println(System.getProperty("java.library.path"));
And got this:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
To guarantee that Eclipse updates java.library.path correctly at run time, the Native library location item must be set to the folder containing the JRI jars (/usr/local/lib/R/site-library/rJava/jri in my case):
Just select the item and click Edit... to change its value.
you can try to add the jri.dll(in your rJava/jri/x64 package) on the System environment variable path,like this:(sorry I cann't put the picture on it )
in that way ,then restart your IDE and just run your test.

How to use matlabcontrol api and jboss

thanks in advance for attention.
It's the first time i am writing on this site (quite newbie :) )
I previously read question of a user asking for my same problem. Although i read a lot i could not find a solution.
Problem:
I am trying to use MatlabControl jar (http://code.google.com/p/matlabcontrol/) to "call" matlab within my java code.
When i try this api within a normal java application to try it (including matlabcontrol.jar in the buildpath) everything works perfectly.
My issue is to make it work on an ejb module with jboss 5 AS:
i can deploy the ejb module and i can see classes of the matlabcontrol.jar (which i put in server/default/lib folder), but it is not working and is returning me the following exception:
Caused by: java.lang.NullPointerException
at java.io.File.<init>(File.java:251)
at matlabcontrol.Configuration.getSupportCodeLocation(Configuration.java:227)
at matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:278)
at matlabcontrol.RemoteMatlabProxyFactory.requestProxy(RemoteMatlabProxyFactory.java:116)
at matlabcontrol.RemoteMatlabProxyFactory.getProxy(RemoteMatlabProxyFactory.java:134)
at matlabcontrol.MatlabProxyFactory.getProxy(MatlabProxyFactory.java:81)
that lead me to the following lines:
URL url = Configuration.class.getProtectionDomain().getCodeSource().getLocation();
File file = new File(url.toURI().getPath()).getCanonicalFile();
The very strange thing is that very very rarely, after restarting jboss and re-deploying the ejb module, the system works!.
I really don't know if i have to modify the source code of these last 2 lines (as if it is a problem of not properly getting the location of the jar code) or to set some configuration files of jBoss to set the classpath differently.
Thanks again in advance.
Any help would be very appreciate.
The mistake was in the code to find the location of the jar at runtime.
I printed the path, which ended with "!" and double slash, so I removed these chars and I was finally able to make this API work.

Overriding acm.program init() method; does Java have to be this hard?

Java problems
I am a student of Java. I managed to write about 15 Java programs so far and get them working on the PC. But I have not yet written a init() method like my latest assignment requires in order to initialize some instance variables. The compiler tells me that my init() method is attempting to override the final init() method in the acm.program. Isn’t that what an init() method is supposed to do? After exhausting all avenues on PC for the last week, I thought maybe it is an Eclipse problem on the PC. All the example code in the Java documentation shows little Mac windows. So I thought I would try moving my code to a Mac running Lion OS 10.7.2.
Switching to MAC environment.
The Mac claims to have Java installed but I think it’s just the run time environment, not a development environment. All I could find for applications is the Java VisualVM, which I assume is the virtual machine so there is no java development software. So… I downloaded Eclipse for Mac from Stanford’s website and got Eclipse IDE for Java Developers Version: Helios Service Release 2 and tried to run a simple program which included an import statement.
The import acm.program.*; statement is giving the compiler a problem: "acm cannot be resolved”. After researching this I think the problem is I have not downloaded the acm.jar archive and added that to my build path. Why this isn’t already done for me, as part of Eclipse I have no clue. I guess everything has to be difficult.
So I downloaded the acm.jar archive and it’s sitting in my download folder. I tried double clicking it and thankfully the mac won’t execute it. I tried dragging it into my source folder in Eclipse and then adding it to the build path. Once in the build path, Eclipse tells me the jar is missing. So I removed it from the build path and instead from inside Eclipse went to Properties/Java Build Path/Libraries/add External JARS… and navigated to my downloads folder where the acm.jar folder is to select the JAR. However, Eclipse seems to be looking for a .jar;.zip file, which there are none because my Mac helpfully already unzipped the folder. So I changed the open window to look for all files (.) and now I see individual .java files that are too numerous to add to the build path individually.
So back to the PC and download the acm.jar zip file and copy it over to the Mac in unzipped form and again add it to the build path as a zip file. This resolved the compiler error and my simple program executed on the Mac!
Next I will try my program with the init() method to see if that now works. Nope. Same problem on the Mac. This init method causes the following error: Multiple markers at this line
overrides acm.program.Program.init
Cannot override the final method from
Program
public void init() {
canvas = new HangmanCanvas();
add(canvas);
}
Does it have to be this hard or am I missing something?
Generally Macs have the whole JDK installed. Eclipse is nice, though.
This "acm" package isn't installed because it's not any kind of standard thing; this is like asking why your refrigerator doesn't come with asparagus already in it.
That last dialog was the right one; you need the original jar file. Try again, right-click and "Save As..." the link to save the file from your browser.
See 3. I find it particularly funny that anybody would use a Windows computer to make up for shortcomings of a Mac; in reality the Mac is infinitely more flexible and more powerful.
If you got a message that complains you're trying to override a final method, then you are indeed trying to do something wrong; final actually means "You're not allowed to override this." Perhaps you didn't fully understand the instructions for the assignment.
It gets better, I promise. Just be sure to use each of these annoyances as a learning experience.
There is no reasons why Java for the Mac would be any better than Java for the PC. The language and tools should work the same ... assuming that you are using the same versions of the language and similar versions of the tools.
Your problem with init is nothing to do with PCs versus Macs. So don't waste your time switching platforms to try to fix it. You need to figure out what the
On the face of is, the compiler / IDE is telling you the truth. Java won't let you override a final method. In fact the whole point of declaring a method to be final is to prevent overloading.
However, this does not make sense. According to the documentation I found here, the acm.program.Program.init() method is designed to be overridden. So why won't it let you?
I suspect that the cause of your problems is that you've downloaded or been given a copy of the JAR file that someone has messed around with. Someone has changes the method to be final (for some reason best kown to themselves), compiled it and put it up for people to download. Google is not always your friend ...
So, what I suggest you do is review all of the handouts and the files that were provided to find either the copy of the JAR that is provided, or the instructions on WHERE to download it from. Then replace the copy of the JAR you are currently using with the recommended one.
Why this isn’t already done for me, as part of Eclipse I have no clue. I guess everything has to be difficult.
How is Eclipse supposed to know what this "acm" stuff is? Which version you require? Where to download it from?