简体   繁体   English

设备工作正常但内置 jar

[英]Device working properly but not in built jar

I have a project which uses a passport reader for scanning documents, the properly way to use it is initialyze the device before start using it.我有一个使用护照阅读器扫描文件的项目,使用它的正确方法是在开始使用之前初始化设备。 The fact is when i run my project to test it (im using Intellij on Win10), it works perfectly fine without issues, but when i build a jar to export it (including the passport reader libraries) shows the next message:事实是当我运行我的项目来测试它时(我在 Win10 上使用 Intellij),它工作得非常好,没有问题,但是当我构建 jar 来导出它时(包括护照阅读器库)显示下一条消息:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "<local2>" is null
at Pr22.DocumentReaderDevice.init(Unknown Source)
at Pr22.DocumentReaderDevice.<init>(Unknown Source)
at Testing.PassportReaderOpen.main(PassportReaderOpen.java:15)

I looked at the method were the exception points and crashes just when uses an object of the library (Pr22.jar) for the first time in my class PassportReader.java but i can't find nothing about that "local2" string.我在我的 class PassportReader.Z93F725A07423FE1C889F448B33D21F46 中第一次使用库(Pr22.jar)的 object 时查看了异常点和崩溃的方法。

To put you in context this is the PassportReader class:在上下文中,这是 PassportReader class:

package Testing;

import Pr22.DocScanner;
import Pr22.DocumentReaderDevice;
import PrIns.Exceptions.General;

public class PassportReaderOpen {

    static DocumentReaderDevice documentReader = null;
    static DocScanner scanner;

    public static void main(String[] args) {
        try {
            System.out.println("Opening device");
            documentReader = new DocumentReaderDevice();
            documentReader.useDevice(0);
            scanner = documentReader.getScanner();
            System.out.println("The device " + documentReader.getDeviceName() + " is opened.");
            documentReader.close();
            System.out.println("Device closed");
        } catch (General general) {
            general.printStackTrace();
        }
    }

}

As you can see the crash happens after the object has been declared, so the library Pr22 should be included in the built jar am i correct?如您所见,在声明 object 之后发生了崩溃,因此库 Pr22 应该包含在构建的 jar 中,对吗?

Ok i solved it, i was exporting the jar with the "extract to the target jar" option in the artifact builder, the Pr.jar from the passport reader never was in the classpath so my app jar couldn't find it.好的,我解决了,我正在使用工件生成器中的“提取到目标 jar”选项导出 jar,来自护照阅读器的 Pr.jar 从未在类路径中,所以我的应用程序 Z689954FCBF432492DAC404 找不到它。 Changing that option to "copy to the output directory and link via manifest" and putting my Pr.jar in the root directory of my recent builded app jar do the trick.将该选项更改为“复制到 output 目录并通过清单链接”并将我的 Pr.jar 放在我最近构建的应用程序 jar 的根目录中。

There you have it:你有它:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM