News
OpenMinds & MindPixel
ICTCLAS JNI invokation in Eclipse
Environment: Ubuntu 8.04, Java 6
Step 1: Install libstdc++.so.5
Ubuntu 8.04 has libstdc++.so.6 by default, but JNI requires libstdc++.so.5. A easy way to install this library is via Synaptic Package Manager.
To launch Synaptic, choose System > Administration > Synaptic Package Manager, then search libstdc++, and tick the package called libstdc++5
Step 2: Write a test Java file
Start a new Java file, and import the ICTCLAS30 interface by
import ICTCLAS.I3S.AC.ICTCLAS30;
The hierarchy in the way which the ICTCLAS30.class stored is important, changing the hierarchy may result in failure of JNI invocation.
The following code will create a instance of ICTCLAS30, and initialize it.
public class test{
public static void main(String [] args){
ICTCLAS30 testICTCLAS30 = new ICTCLAS30;
//Initial Directory Path, where file Configure.xml and Data directory stored
String path="/conf/and/data/path";
//the default encoding is "GBK" can set it with "UNICODE","UTF-8","UTF-7", etc
String encoding="UTF-8";
//initialization
testICTCLAS30.ICTCLAS_Init(path.getBytes(), encoding.getBytes());
}}
save this file, and run it. You will get a error message at this stage, which relates to UnsatisfiedLinkError. Don't worry, the next step will solve this problem.
Step 3: Add the LD_LIBRARY_PATH variable in the Eclipse environment variables
To launch the Run Configuration panel, Choose Run -> Run Configuration
Select the Java application that we just created, and click the 'Environment' tag.
Create a new variable, name it LD_LIBRARY_PATH, and the value is the path of the parent folder of libICTCLAS30.so (i.e /lib/ictclas/Linux_JNI_32bit/sample/Linux_JNIDemo_32Bit_sample).
Save the settings, now you are able to call native ICTCLAS functions from Java!
Also available in: Atom