Code Monkey home page Code Monkey logo

Comments (8)

yonran avatar yonran commented on July 24, 2024 1

The stack trace indicates that there was an error loading or initializing com.sun.jna.Native. I’m not sure yet what went wrong, because NoClassDefFoundError should have another Caused by… stack trace the first time it happens when running a program, but your stack trace does not.

Early in your main, would you try initializing com.sun.jna.Native yourself to see whether it also throws NoClassDefFoundError? Then hopefully we can find out what the first Caused by is.

Class.forName("com.sun.jna.Native")

libjna-java is in the newest version: 4.2.2-3.

Are you using mvn to manage java dependencies, or are you including jnasmartcardio’s jar manually?

Why is the library trying to use WinSCard on Linux?

WinSCard.java is the name of the class I use to wrap both the PC/SC and WinSCard API. On linux, I try to load the libpcsclite.so.1 library instead of WinSCard.dll.

from jnasmartcardio.

yonran avatar yonran commented on July 24, 2024 1

I'm using gradle

The reason that I ask is that you may not be using the newest Debian package libjna-java if gradle is also providing the jna transitive dependency (since jnasmartcardio depends on jna). To be sure which version of JNA you are using, print the URL of the file:

// If you construct new Smartcardio(), then the provider comes from your class’s ClassLoader
String className = "com.sun.jna.Native";

// replace MyClass.class with your own class name, or getClass() if it’s not a static method
System.out.println(MyClass.class.getClassLoader().getResource(className.replace('.', '/') + ".class"));

// If you use a named security.provider, then JCA uses the System ClassLoader
// http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/sun/security/jca/ProviderConfig.java#l212
System.out.println(ClassLoader.getSystemClassLoader().getResource(className.replace('.', '/') + ".class"));

This should print out whether you are currently using the jna jar that you think you are.

If you want to use the newest version of jna through gradle (as opposed to 4.0.0 which jnasmartcardio currently depends on), you may want to add an explicit dependency on the newest version: compile group: 'net.java.dev.jna', name: 'jna', version: '4.5.2'. This is probably bigger than the system one since it includes shared libraries for all possible platforms.

If you want to use Debian’s version of jna, you may want to exclude the transitive dependency from jnasmartcardio to jna. See Gradle: Excluding transitive module dependencies.

from jnasmartcardio.

mbe24 avatar mbe24 commented on July 24, 2024

Thanks for your answer. I'll have access to the code again tomorrow. I'll try to initialize com.sun.jna.Native then.

I'm using gradle, but I rely on the Maven repositories to manage my dependencies.

from jnasmartcardio.

mbe24 avatar mbe24 commented on July 24, 2024

Thanks @yonran!

I excluded the transitive dependencies adding:

    compile("io.github.jnasmartcardio:jnasmartcardio:0.2.7") {
        exclude group: 'net.java.dev.jna', module: 'jna'
        exclude group: 'net.java.dev.jna', module: 'jna-platform'
    }

The output from you code snippet above was

jar:file:/home/pi/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna/4.5.1/65bd0cacc9c79a21c6ed8e9f588577cd3c2f85b9/jna-4.5.1.jar!/com/sun/jna/Native.class
jar:file:/home/pi/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna/4.5.1/65bd0cacc9c79a21c6ed8e9f588577cd3c2f85b9/jna-4.5.1.jar!/com/sun/jna/Native.class

after excluding the dependencies it's

null
null

The code works though!

Are you still interested in that full stack trace?

from jnasmartcardio.

yonran avatar yonran commented on July 24, 2024

If classLoader.getResource("com/sun/jna/Native.class") returns null, then you won’t be able to use JNA at all, and nothing will work. Presumably you executed these test lines on the development machine rather than on machine with the smart card reader?

If the stack trace for the failure is readily available, I would like to see it. It might indicate whether I should upgrade the dependency from jnasmartcardio to jna in my pom.xml.

from jnasmartcardio.

mbe24 avatar mbe24 commented on July 24, 2024

If you want to use the newest version of jna through gradle (as opposed to 4.0.0 which jnasmartcardio currently depends on), you may want to add an explicit dependency on the newest version: compile group: 'net.java.dev.jna', name: 'jna', version: '4.5.2'.

Sorry for the delayed answer. I've added an explicit dependency to jna (version 5.0.0, though) as you told me. Now it works.
This is the output of the code snippet above:

jar:file:/home/pi/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna/5.0.0/a73c9c974cf7d3b1b84bca99e30d16ec3f371b44/jna-5.0.0.jar!/com/sun/jna/Native.class
jar:file:/home/pi/.gradle/caches/modules-2/files-2.1/net.java.dev.jna/jna/5.0.0/a73c9c974cf7d3b1b84bca99e30d16ec3f371b44/jna-5.0.0.jar!/com/sun/jna/Native.class

from jnasmartcardio.

coder84-droid avatar coder84-droid commented on July 24, 2024

I am in the process of upgrating the maven dependencies to be able to compatible with Java 17 and now when I use the latest 5.13.0, I get the error. Could not load terminal factory! Error constructing implementation (algorithm: PC/SC, provider: JNA2PCSC, class: jnasmartcardio.Smartcardio$JnaTerminalFactorySpi)
<groupId>net.java.dev.jna</groupId> <artifactId>jna</artifactId> <version>5.13.0</version>
Is there a compatible jnasmartcardio?

from jnasmartcardio.

martinpaljak avatar martinpaljak commented on July 24, 2024

You might want to try this: https://github.com/martinpaljak/apdu4j-jnasmartcardio/releases/tag/v0.2.7%2B230522

Via https://gist.github.com/martinpaljak/c77d11d671260e24eef6c39123345cae

from jnasmartcardio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.