如何在Java中使用Nitgen eNBioScan-C1指纹扫描仪?

时间:2018-01-05 14:24:43

标签: java swing netbeans dll java-native-interface

问题

我尝试在netbeans的java代码中加载NBioBSPJNI.dll文件。它给出了以下异常

  

" java.lang.UnsatisfiedLinkError:C:\ DLL \ NBioBSPJNI.dll:无法找到   依赖图书馆"。

我试图解决的问题

我在java.library.path中粘贴了dll文件。也在sysWOW64文件夹中。

我认为这是一个JNI DLL文件。我怎样才能在我的java代码中使用这个JNI dll来连接指纹扫描仪设备。

我的源代码:

包装bioenable;

import com.nitgen.SDK.BSP.NBioBSPJNI;

公共类NBioAPI_JavaUITest扩展了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

}

错误截图是: enter image description here

1 个答案:

答案 0 :(得分:0)

看起来您的代码无法加载它所依赖的库。

尝试使用超级简单的测试用例来测试您的代码。像这样:

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

然后,尝试找到库NBioBSPJNI.dll取决于。你可以随时点击PATH。请注意,JVM可以加载System.load指定的共享库,但是库使用的共享库必须对JVM可见。

看起来您的代码尝试加载依赖于不可见库的内容。我建议您将C:\\DLL添加到PATH