I wrote a stand alone Java program (THAT WORKS) it calls a native library created from a C program by generating the libipmi_agent.so lib, but running it in a web-app in tomcat is giving the following error:
native library call java.lang.reflect.InvocationTargetException
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
java.lang.UnsatisfiedLinkError: org.qcri.power.util.IPMIAgent.ipmi_agent_init()I
org.qcri.power.util.IPMIAgent.ipmi_agent_init(Native Method)
org.qcri.power.util.IPMIAgent.main(IPMIAgent.java:18)
...
Here is my Java class:
package org.qcri.power.util;
public class IPMIAgent
{
private native int ipmi_agent_init();
private native void ipmi_agent_close();
private native int ipmi_agent_read_current_value();
static
{
System.loadLibrary("ipmi_agent");
}
// The main program
public static int main(String[] args)
{
int i, v=0;
IPMIAgent ipmiagent = new IPMIAgent();
ipmiagent.ipmi_agent_init();
for (i = 0; i < 100; i++)
{
try{
v = ipmiagent.ipmi_agent_read_current_value();
System.out.println("Current value is " + v);
Thread.currentThread().sleep(1000);
}
catch(InterruptedException ie){
}
}
return v;
}
}
the libipmi_agent.so is in the same class folder with the the above Java class under /webapps/myapp/WEB_INF/classes.
is the position of the file correct? anyone has an idea?
Thanks in advance.
Building a stand alone program didn’t work on tomcat because the standalone class included in the web-app structure had a package name, so tomcat couldn’t find the right path since the native library generated was the one from the stand alone app with no package name.