Neeraj Gangwal
Neeraj Gangwal

Reputation: 31

How to use Nitgen eNBioScan-C1 fingerprint scanner in Java?

The problem

I tried to load the NBioBSPJNI.dll file in my java code in netbeans. It gives the following exception

"java.lang.UnsatisfiedLinkError: C:\DLL\NBioBSPJNI.dll: Can't find dependent libraries".

What I have tried to resolve

I pasted the dll files in java.library.path. Also in sysWOW64 folder.

I think this is a JNI dll file. How could I use this JNI dll in my java code to connect the fingerprint scanner device.

My source code:

package bioenable;

import com.nitgen.SDK.BSP.NBioBSPJNI;

public class NBioAPI_JavaUITest extends javax.swing.JDialog {

/** Creates new form NBioAPI_JavaUITest */
public NBioAPI_JavaUITest(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();

    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent e) {
            Closing();
            System.exit(0);
        }
    });

    bsp = new NBioBSPJNI();

    if (CheckError())
        return ;

    setTitle("NBioAPI_JavaUITest BSP version: " + bsp.GetVersion());

    bsp.OpenDevice();

    if (CheckError())  {
        btnCapture.setEnabled(false);
        btnEnroll.setEnabled(false);
    }
    else
        labelStatus.setText("NBioBSP Initialize success");
}

public void dispose()
{
    if (bsp != null) {
        bsp.CloseDevice();
        bsp.dispose();
        bsp = null;
    }
}

private Boolean CheckError()
{
    if (bsp.IsErrorOccured())  {
        labelStatus.setText("NBioBSP Error Occured [" + bsp.GetErrorCode() + "]");
        return true;
    }

    return false;
}

private Boolean SetWindowOption()
{
    if (winOption != null)
        winOption = null;

    winOption = bsp.new WINDOW_OPTION();

    if (ShowStyle.isSelected(rbtnPopup.getModel()))  {
        winOption.WindowStyle = NBioBSPJNI.WINDOW_STYLE.POPUP;

        if (checkNFI.isSelected())
            winOption.WindowStyle |= NBioBSPJNI.WINDOW_STYLE.NO_FPIMG;

        if (checkNTMW.isSelected())
            winOption.WindowStyle |= NBioBSPJNI.WINDOW_STYLE.NO_TOPMOST;

        if (checkNWP.isSelected())
            winOption.WindowStyle |= NBioBSPJNI.WINDOW_STYLE.NO_WELCOME;
    }
    else  {
        winOption.WindowStyle = NBioBSPJNI.WINDOW_STYLE.INVISIBLE;

        if (checkSFW.isSelected())
            winOption.FingerWnd = FPWindow;
    }

    String szValue;

    szValue = textCaption.getText();

    if (szValue.length() > 0)
        winOption.CaptionMsg = szValue;

    szValue = textCancel.getText();

    if (szValue.length() > 0)
        winOption.CancelMsg = szValue;

    if (checkLThumb.isSelected())
        winOption.DisableFingerForEnroll0 = 0;
    else
        winOption.DisableFingerForEnroll0 = 1;

    if (checkLIndex.isSelected())
        winOption.DisableFingerForEnroll1 = 0;
    else
        winOption.DisableFingerForEnroll1 = 1;

    if (checkLMiddle.isSelected())
        winOption.DisableFingerForEnroll2 = 0;
    else
        winOption.DisableFingerForEnroll2 = 1;

    if (checkLRing.isSelected())
        winOption.DisableFingerForEnroll3 = 0;
    else
        winOption.DisableFingerForEnroll3 = 1;

    if (checkLLittle.isSelected())
        winOption.DisableFingerForEnroll4 = 0;
    else
        winOption.DisableFingerForEnroll4 = 1;

    if (checkRThumb.isSelected())
        winOption.DisableFingerForEnroll5 = 0;
    else
        winOption.DisableFingerForEnroll5 = 1;

    if (checkRIndex.isSelected())
        winOption.DisableFingerForEnroll6 = 0;
    else
        winOption.DisableFingerForEnroll6 = 1;

    if (checkRMiddle.isSelected())
        winOption.DisableFingerForEnroll7 = 0;
    else
        winOption.DisableFingerForEnroll7 = 1;

    if (checkRRing.isSelected())
        winOption.DisableFingerForEnroll8 = 0;
    else
        winOption.DisableFingerForEnroll8 = 1;

    if (checkRLittle.isSelected())
        winOption.DisableFingerForEnroll9 = 0;
    else
        winOption.DisableFingerForEnroll9 = 1;

    try  {
        szValue = textFpColorR.getText();
        winOption.FPForeColorR = Integer.parseInt(szValue);

        szValue = textFpColorG.getText();
        winOption.FPForeColorG = Integer.parseInt(szValue);

        szValue = textFpColorB.getText();
        winOption.FPForeColorB = Integer.parseInt(szValue);

        szValue = textBKColorR.getText();
        winOption.FPBackColorR = Integer.parseInt(szValue);

        szValue = textBKColorG.getText();
        winOption.FPBackColorG = Integer.parseInt(szValue);

        szValue = textBKColorB.getText();
        winOption.FPBackColorB = Integer.parseInt(szValue);
    }
    catch (NumberFormatException e) {
        labelStatus.setText("Invalid Input value");
        return false;
    }

    return true;
}



public void Closing()
{
    dispose();
}

private void rbtnPopupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnPopupActionPerformed
    checkNFI.setEnabled(true);
    checkNTMW.setEnabled(true);
    checkNWP.setEnabled(true);

    textFpColorR.setEnabled(false);
    textFpColorG.setEnabled(false);
    textFpColorB.setEnabled(false);

    textBKColorR.setEnabled(false);
    textBKColorG.setEnabled(false);
    textBKColorB.setEnabled(false);

    checkSFW.setEnabled(false);
}//GEN-LAST:event_rbtnPopupActionPerformed

private void rbtnInvisibleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnInvisibleActionPerformed
    checkNFI.setEnabled(false);
    checkNTMW.setEnabled(false);
    checkNWP.setEnabled(false);

    textFpColorR.setEnabled(true);
    textFpColorG.setEnabled(true);
    textFpColorB.setEnabled(true);

    textBKColorR.setEnabled(true);
    textBKColorG.setEnabled(true);
    textBKColorB.setEnabled(true);

    checkSFW.setEnabled(true);
}//GEN-LAST:event_rbtnInvisibleActionPerformed

private void btnCaptureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCaptureActionPerformed
    labelStatus.setText("Capture start");

    NBioBSPJNI.FIR_HANDLE hFIR = bsp.new FIR_HANDLE();

    if (SetWindowOption() == false)  {
        labelStatus.setText("Set Windows Option failed");
        return ;
    }

    bsp.Capture(NBioBSPJNI.FIR_PURPOSE.VERIFY, hFIR, -1, null, winOption);

    if (CheckError())
        return ;

    hFIR.dispose();
    hFIR = null;

    labelStatus.setText("Capture success");
}//GEN-LAST:event_btnCaptureActionPerformed

private void btnEnrollActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEnrollActionPerformed
    labelStatus.setText("Enroll start");

    NBioBSPJNI.FIR_HANDLE hFIR = bsp.new FIR_HANDLE();

    if (SetWindowOption() == false)  {
        labelStatus.setText("Set Windows Option failed");
        return ;
    }

    bsp.Enroll(null, hFIR, null, -1, null, winOption);

    if (CheckError())
        return ;

    hFIR.dispose();
    hFIR = null;

    labelStatus.setText("Enroll success");
}//GEN-LAST:event_btnEnrollActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            NBioAPI_JavaUITest dialog = new NBioAPI_JavaUITest(new javax.swing.JFrame(), true);
            dialog.setVisible(true);
        }
    });
}

// NBioBSPJNI Variables
NBioBSPJNI                  bsp;
NBioBSPJNI.WINDOW_OPTION    winOption;

// Variables declaration - do not modify//GEN-BEGIN:variables
private java.awt.Canvas FPWindow;
private javax.swing.ButtonGroup ShowStyle;
private javax.swing.JButton btnCapture;
private javax.swing.JButton btnEnroll;
private javax.swing.JCheckBox checkLIndex;
private javax.swing.JCheckBox checkLLittle;
private javax.swing.JCheckBox checkLMiddle;
private javax.swing.JCheckBox checkLRing;
private javax.swing.JCheckBox checkLThumb;
private javax.swing.JCheckBox checkNFI;
private javax.swing.JCheckBox checkNTMW;
private javax.swing.JCheckBox checkNWP;
private javax.swing.JCheckBox checkRIndex;
private javax.swing.JCheckBox checkRLittle;
private javax.swing.JCheckBox checkRMiddle;
private javax.swing.JCheckBox checkRRing;
private javax.swing.JCheckBox checkRThumb;
private javax.swing.JCheckBox checkSFW;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel10;
private javax.swing.JPanel jPanel12;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JLabel labelStatus;
private javax.swing.JRadioButton rbtnInvisible;
private javax.swing.JRadioButton rbtnPopup;
private javax.swing.JTextField textBKColorB;
private javax.swing.JTextField textBKColorG;
private javax.swing.JTextField textBKColorR;
private javax.swing.JTextField textCancel;
private javax.swing.JTextField textCaption;
private javax.swing.JTextField textFpColorB;
private javax.swing.JTextField textFpColorG;
private javax.swing.JTextField textFpColorR;
// End of variables declaration//GEN-END:variables

}

And the error screenshot is: enter image description here

Upvotes: 0

Views: 1259

Answers (1)

Oo.oO
Oo.oO

Reputation: 13405

It looks like your code is not able to load libraries it depends on.

Try to test your code with super simple test case. Something like this:

public class Main {
  static {
    System.load("C:\\DLL\\NBioBSPJNI.dll");
  }
  public static void main(String [] arg) {
    System.out.println("Hello world!");
  }
}

Then, try to locate libraries NBioBSPJNI.dll depends on. You can always put the on PATH. Note that JVM can load shared library specified by System.load, but shared libraries that are used by your library must be visible to JVM.

It looks like your code tries to load something that depends on libraries that are not visible. I suggest to add C:\\DLL to your PATH.

Upvotes: 0

Related Questions