引导层初始化期间发生错误:java.lang.module.ResolutionException

时间:2019-04-09 05:45:22

标签: java

我正在使用指纹设备将指纹注册到MYSQL数据库中。但是,我无法正确运行程序,因为执行该程序时会显示错误。

我对此做了一些研究。在许多论坛上,它都表明这是JRE版本问题,因此我尝试了JRE 9、10和11均未成功

  

启动层初始化期间发生错误   java.lang.module.ResolutionException:模块dpfpenrollment包含   软件包com.digitalpersona.onetouch.ui.swing,模块dpfpverification   将com.digitalpersona.onetouch.ui.swing包导出到dpfpenrollment

实际结果应在MYSQL中注册ID,用户名和指纹。

这是用于创建UserInterface和UserDatabase实例并运行UserInterface的代码

package com.my.apiit;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


/**
 * Creates UserInterface and UserDatabase instances and runs UserInterface.
 */
public class AppFingerPrintToDb {

    public static void main (String[] args) {

        try {
            ExecutorService exec = Executors.newCachedThreadPool();
            exec.execute(new ConsoleUserDbManager());

            exec.shutdown();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
package com.my.apiit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;
import java.util.concurrent.LinkedBlockingQueue;

import com.digitalpersona.onetouch.DPFPDataPurpose;
import com.digitalpersona.onetouch.DPFPFeatureSet;
import com.digitalpersona.onetouch.DPFPFingerIndex;
import com.digitalpersona.onetouch.DPFPGlobal;
import com.digitalpersona.onetouch.DPFPSample;
import com.digitalpersona.onetouch.DPFPTemplate;
import com.digitalpersona.onetouch.capture.DPFPCapture;
import com.digitalpersona.onetouch.capture.DPFPCapturePriority;
import com.digitalpersona.onetouch.capture.event.DPFPDataEvent;
import com.digitalpersona.onetouch.capture.event.DPFPDataListener;
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusAdapter;
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusEvent;
import com.digitalpersona.onetouch.processing.DPFPEnrollment;
import com.digitalpersona.onetouch.processing.DPFPFeatureExtraction;
import com.digitalpersona.onetouch.processing.DPFPImageQualityException;
import com.digitalpersona.onetouch.readers.DPFPReadersCollection;
import com.digitalpersona.onetouch.verification.DPFPVerification;
import com.digitalpersona.onetouch.verification.DPFPVerificationResult;

/**
 * Implementation of UserInterface.Factory interface that creates a console-based user interface
 */
public class ConsoleUserDbManager implements Runnable  {


    public void run() {
        System.out.println("\n*** Console UI ***");

        String activeReader = null;
        boolean readerSelected = false;

        activeReader = selectReader(activeReader);
        readerSelected = true;

        int res;
        while ((res = MenuShow(mainMenu, MENU_WITH_EXIT)) != exitItem.getValue()) try {
            switch (res) {
            /*case MAIN_MENU_ADD:
                //addUser();
                break;*/
            case MAIN_MENU_ENROLL:
                addUser(activeReader);              
                break;
            case MAIN_MENU_VERIFY:
                verify(activeReader);
                break;          
            }
        } catch (Exception e) { }
    }

    /**
     * Console menu item
     */
    private static class MenuItem
    {
        private String text;
        private int value;

        /**
         * Creates a menu item
         *
         * @param text  item text
         * @param value value to return if item is chosen
         */
        public MenuItem(String text, int value) {
            this.text = text;
            this.value = value;
        }

        /**
         * Returns the menu item's text
         *
         * @return menu item text
         */
        public String getText() {
            return text;
        }

        /**
         * Returns the menu item's associated value
         *
         * @return associated value
         */
        public int getValue() {
            return value;
        }
    }

    /**
     * Specifies that menu should be appended with "Back" item
     */
    private static final int MENU_WITH_BACK = 2;

    /**
     * Specifies that menu should be appended with "Exit" item
     */
    private static final int MENU_WITH_EXIT = 1;

    /**
     * "Exit" menu item
     */
    private static final MenuItem exitItem = new MenuItem("Exit the application", -1);

    /**
     * "Back" menu item
     */
    private static final MenuItem backItem = new MenuItem("Return to the previous menu", -2);


    private static final int MAIN_MENU_ENROLL = 102;
    private static final int MAIN_MENU_VERIFY = 103;

    private static final Vector<MenuItem> mainMenu;
    static {
        mainMenu = new Vector<MenuItem>();
        mainMenu.add(new MenuItem("Add User And Perform fingerprint enrollment", MAIN_MENU_ENROLL));
        mainMenu.add(new MenuItem("Perform fingerprint verification", MAIN_MENU_VERIFY));
    }


    private int MenuShow(Vector<MenuItem> menu, int nMenuFlags) {
        int choice = 0;

        if (menu == null)
            return choice;

        while (true) {
            System.out.println();
            for (int i = 0; i < menu.size(); ++i)
                System.out.printf("%d: %s\n", i + 1, menu.elementAt(i).getText());

            StringBuilder sb = new StringBuilder();
            sb.append(String.format("Choose an option (1 - %d", menu.size()));
            if ((nMenuFlags & MENU_WITH_BACK) != 0) {
                System.out.printf("\nR: %s\n\n", backItem.getText());
                sb.append(", R");
            }
            if ((nMenuFlags & MENU_WITH_EXIT) != 0) {
                System.out.printf("\nE: %s\n\n", exitItem.getText());
                sb.append(", E");
            }
            sb.append("): ");

            String userInput = ShowDialog(sb.toString());

            if ((nMenuFlags & MENU_WITH_EXIT) != 0 && userInput.equalsIgnoreCase("E")) {
                choice = exitItem.getValue();
                break;
            }
            if ((nMenuFlags & MENU_WITH_BACK) != 0 && userInput.equalsIgnoreCase("R")) {
                choice = backItem.getValue();
                break;
            }

            int nInput;

            try {
                nInput = Integer.parseInt(userInput);
            } catch (NumberFormatException e) {
                System.out.printf("\nInvalid input: \"%s\"\n", userInput);
                continue;
            }

            if (nInput < 1 || nInput > menu.size()) {
                System.out.printf("\nIncorrect choice: \"%s\"\n", userInput);
                continue;
            }

            choice = menu.elementAt(nInput - 1).getValue();
            break;
        }

        System.out.println();
        return choice;
    }

    /**
     * Adds user to the database
     */
    private void addUser(String activeReader) {

        System.out.printf("Adding person to the database...\n");
        String username = ShowDialog("Enter a name: ");

        register(activeReader,username);

        /*if (username != null) {
            System.out.printf("\"%s\" was added to the database.\n", username);
        } else {
            System.out.printf("\"%s\" was not added to the database.\n", username);
        }*/

    }

    /**
     * register() looks for the user in the database, invokes CreateRegistrationTemplate(),
     * and stores the template in the database.
     *
     * @param activeReader reader to use for fingerprint acquisition
     */
    private void register(String activeReader,String username) {

        UserDAO userDAO = UserDAO.getInstance();
        UserDb userDb = userDAO.selectUser(username);

        if(userDb != null){
            System.err.println("User already exist...");
            return;
        }

        System.out.printf("Performing fingerprint enrollment...\n");


        try {
            DPFPFingerIndex finger = DPFPFingerIndex.values()[1];

            DPFPFeatureExtraction featureExtractor = DPFPGlobal.getFeatureExtractionFactory().createFeatureExtraction();
            DPFPEnrollment enrollment = DPFPGlobal.getEnrollmentFactory().createEnrollment();

            while (enrollment.getFeaturesNeeded() > 0)
            {
                DPFPSample sample = getSample(activeReader, 
                        String.format("Scan your finger (%d remaining)\n",  enrollment.getFeaturesNeeded()));
                if (sample == null)
                    continue;

                DPFPFeatureSet featureSet;
                try {
                    featureSet = featureExtractor.createFeatureSet(sample, DPFPDataPurpose.DATA_PURPOSE_ENROLLMENT);
                } catch (DPFPImageQualityException e) {
                    System.out.printf("Bad image quality: \"%s\". Try again. \n", e.getCaptureFeedback().toString());
                    continue;
                }

                enrollment.addFeatures(featureSet);
            }

            DPFPTemplate template = enrollment.getTemplate();
            // write to database 
            userDb = new UserDb();
            userDb.setUserName(username);
            userDb.setFingerPrint(template.serialize());

            userDAO.insertUser(userDb.getUserName(), userDb.fingerPrint);
            //-- write to a specific file
            /*FileOutputStream stream;
                        try {
                            stream = new FileOutputStream(new File("d:/fingerPrint/sample.fpt"));
                            stream.write(template.serialize());
                            stream.close();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }*/

            System.err.println("Congratulation your fingerprint is enrolled in database..");
        } catch(UserDbException e){
            System.out.printf(e.getMessage() + "\n"); 
        } catch (DPFPImageQualityException e) {
            System.out.printf("Failed to enroll the finger.\n");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }            
    }

    /**
     * Acquires fingerprint from the sensor and matches it with the registration templates
     * stored in the database.
     *
     * @param activeReader fingerprint reader to use
     */
    private void verify(String activeReader ) {
        System.out.printf("Performing fingerprint verification...\n");
        String userName = ShowDialog("Enter the name of the person to be verified: ");

        UserDAO userDAO = UserDAO.getInstance();
        UserDb user =userDAO.selectUser(userName);

        if (user == null) {
            System.out.printf("\"%s\" was not found in the database.\n", userName);
        } else {
            if (user == null) {
                System.out.printf("No fingers for \"%s\" have been enrolled.\n", userName);
            } else {
                try {                       
                    DPFPSample sample = getSample(activeReader, "Scan your finger\n");
                    if (sample == null)
                        throw new Exception();

                    DPFPFeatureExtraction featureExtractor = DPFPGlobal.getFeatureExtractionFactory().createFeatureExtraction();
                    DPFPFeatureSet featureSet = featureExtractor.createFeatureSet(sample, DPFPDataPurpose.DATA_PURPOSE_VERIFICATION);

                    DPFPVerification matcher = DPFPGlobal.getVerificationFactory().createVerification();
                    matcher.setFARRequested(DPFPVerification.MEDIUM_SECURITY_FAR);

                    try {
                        //-- reading from User
                        byte[] data = user.getFingerPrint();
                        DPFPTemplate t = DPFPGlobal.getTemplateFactory().createTemplate();
                        t.deserialize(data);

                        //--- reading from file 
                        /*FileInputStream stream = new FileInputStream("d:/fingerPrint/sample.fpt");
                            byte[] data = new byte[stream.available()];
                            stream.read(data);
                            stream.close();
                            DPFPTemplate t = DPFPGlobal.getTemplateFactory().createTemplate();
                            t.deserialize(data);
                         */
                        //setTemplate(t);

                        //-----verfiy -------------
                        if (t != null) {
                            DPFPVerificationResult result = matcher.verify(featureSet, t);
                            if (result.isVerified()) {
                                //System.err.println("Matching finger: Successfully Matched" ,(double)result.getFalseAcceptRate()/DPFPVerification.PROBABILITY_ONE);
                                System.err.println("Matching finger: Successfully Matched");
                                ShowDialog("\nPress enter to continue ....");
                                return;
                            }
                        }
                    } catch (Exception ex) {
                        System.out.printf("Failed to perform verification.");
                    }                        
                } catch (Exception e) {
                    System.out.printf("Failed to perform verification.");
                }
                //System.out.printf("No matching fingers for \"%s\" were found.\n", userName);
                System.out.printf("No matching fingers for "+ userName+" were found.\n");
                ShowDialog("\nPress enter to continue ....");
            }
        }

    }


    /**
     * selectReader() stores chosen reader in *pActiveReader
     * @param activeReader currently selected reader
     * @return reader selected
     * @throws IndexOutOfBoundsException if no reader available
     */
    String selectReader(String activeReader) throws IndexOutOfBoundsException {
        DPFPReadersCollection readers = DPFPGlobal.getReadersFactory().getReaders();
        if (readers == null || readers.size() == 0)
            throw new IndexOutOfBoundsException("There are no readers available");

        int res = 0;
        return readers.get(res).getSerialNumber();            
    }

    /**
     * Acquires a fingerprint sample from the specified fingerprint reader
     *
     * @param activeReader Fingerprint reader to use for acquisition
     * @return sample acquired
     * @throws InterruptedException if thread is interrupted
     */
    private DPFPSample getSample(String activeReader, String prompt)
            throws InterruptedException
    {
        final LinkedBlockingQueue<DPFPSample> samples = new LinkedBlockingQueue<DPFPSample>();
        DPFPCapture capture = DPFPGlobal.getCaptureFactory().createCapture();
        capture.setReaderSerialNumber(activeReader);
        capture.setPriority(DPFPCapturePriority.CAPTURE_PRIORITY_LOW);
        capture.addDataListener(new DPFPDataListener()
        {
            public void dataAcquired(DPFPDataEvent e) {
                if (e != null && e.getSample() != null) {
                    try {
                        samples.put(e.getSample());
                    } catch (InterruptedException e1) {
                        e1.printStackTrace();
                    }
                }
            }
        });
        capture.addReaderStatusListener(new DPFPReaderStatusAdapter()
        {
            int lastStatus = DPFPReaderStatusEvent.READER_CONNECTED;
            public void readerConnected(DPFPReaderStatusEvent e) {
                if (lastStatus != e.getReaderStatus())
                    System.out.println("Reader is connected");
                lastStatus = e.getReaderStatus();
            }
            public void readerDisconnected(DPFPReaderStatusEvent e) {
                if (lastStatus != e.getReaderStatus())
                    System.out.println("Reader is disconnected");
                lastStatus = e.getReaderStatus();
            }

        });
        try {
            capture.startCapture();
            System.out.print(prompt);
            return samples.take();
        } catch (RuntimeException e) {
            System.out.printf("Failed to start capture. Check that reader is not used by another application.\n");
            throw e;
        } finally {
            capture.stopCapture();
        }
    }

    private String ShowDialog(String prompt) {
        System.out.printf(prompt);
        try {
            BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
            return stdin.readLine();
        } catch (IOException e) {
            return "";
        }
    }
}



0 个答案:

没有答案