Use jsmile in web application with Apache Tomcat 7 and Linux CentOS 7

The engine.
Post Reply
Yun
Posts: 20
Joined: Mon Oct 17, 2016 8:34 pm

Use jsmile in web application with Apache Tomcat 7 and Linux CentOS 7

Post by Yun »

Hi, SMILE creators,

I have been trying to make jsmile work (libjsmile.so) in a web application with Apache Tomcat 7 on a Linux CentOS 7 server using all the methods I could find on the Internet, but I still haven't succeeded.

I was able to use this wrapper (libjsmile.jnilib downloaded on Nov. 24, 2014) as a Java application or a web application with Apache Tomcat 7 on a Mac (with jdk 1.6). And I was able to load libjsmile.so as a Java application on the CentOS 7 server (with jre 1.8). The error starts to occur when I want to load libjsmile.so in a web application with Apache Tomcat 7 in the CentOS 7 (with jre 1.8). I have tried to add LD_LIBRARY_PATH (and/or JAVA_OPTS="-Djava.library.path=.....") to the Tomcat configuration file (tomcat.conf) with the path that I put the libjsmile.so inside (e.g./usr/share/java/tomcat/lib). Here is the error:

java.lang.UnsatisfiedLinkError: smile.Wrapper.nativeStaticInit()V
smile.Wrapper.nativeStaticInit(Native Method)
smile.Wrapper.<clinit>(Wrapper.java:59)

I have tried using System.loadLibrary() in Wrapper.java or used System.load() with an absolute path:

Code: Select all

package smile;

public abstract class Wrapper 
{
	public Wrapper() 
	{ 
	    ptrNative = createNative(null); 
	}
	
	public Wrapper(Object param)
	{
	    ptrNative = createNative(param);
	}
	
	public void dispose() 
	{
		deleteNative(ptrNative);
		ptrNative = 0;
	}
	
	
	protected void finalize() 
	{ 
	    deleteNative(ptrNative); 
    }
	
	protected abstract long createNative(Object param);
	protected abstract void deleteNative(long nativePtr);
	private static native void nativeStaticInit();

	protected long ptrNative = 0;
	
	static 
	{
	    System.loadLibrary("jsmile");
	    nativeStaticInit();
    }
}
If it still can't work on CentOS, do you think we should try Ubuntu instead?

I am not that experienced in web development and Linux, and am feeling very helpless now. I couldn't find any instructions from the website and forum (sorry if I missed them). Could you give me some step-by-step instructions? Any help is deeply appreciated!

Thanks,
Yun
ISP, UPitt
piotr [BayesFusion]
Site Admin
Posts: 63
Joined: Mon Nov 06, 2017 6:41 pm

Re: Use jsmile in web application with Apache Tomcat 7 and Linux CentOS 7

Post by piotr [BayesFusion] »

Hi, please try instruction listed below.

1. Download jSmile dedicated for your Operating System
2. Obtain SMILE license from Bayesfusion downloads site
3. Create Web Project in your Java IDE i.e. Dynamic Web Project in Eclipse
4. Paste jSmile archive content into your-project/WEB-INF/lib folder
5. Add VM argument to CATALINA_OPTS - -Djava.library.path="path/to/pasted/jsmile/binaries"
6. Create simple servlet. It doesn't matters how you name it.
7. Before you use any SMILE class, you need to paste your license - for example, just paste it into servlet get method.
8. Write some jSmile code ex.

Code: Select all

         Network net = new Network();
         int parentHandle = net.addNode(Network.NodeType.CPT);
         for (int i = 0; i < 10; i++)
             net.addArc(parentHandle, net.addNode(Network.NodeType.CPT));

         String[] childs = net.getChildIds(parentHandle);
         PrintWriter responseWriter = response.getWriter();

         for (String childId : childs)
             responseWriter.append(childId + "\n");
     
9. Export WAR archive
10. Copy archive to tomcat webapps folder
11. Run Tomcat

If it doesn't work, please list your error stack.
Post Reply