javax.smartcardio.* is not found on Open JDK 11(Redhat)

8.1k Views Asked by At

I am using Redhat's OpenJDK 11 to communicate with a smart card on the Windows. But I have a problem with compiling. It said cannot find javax.smartcardio library.

Enviornment : Redhat OpenJDK 11, Intellij, Kotlin, Gradle

> Task :compileKotlin
e: ~\util\SmartCard.kt: (7, 14): Unresolved reference: smartcardio
e: ~\util\SmartCard.kt: (13, 25): Unresolved reference: CardTerminal
e: ~\util\SmartCard.kt: (13, 41): Unresolved reference: TerminalFactory
e: ~\util\SmartCard.kt: (19, 51): Unresolved reference: CardTerminal
e: ~\util\SmartCard.kt: (25, 43): Unresolved reference: CardTerminal
e: ~\util\SmartCard.kt: (35, 23): Unresolved reference: Card
e: ~\util\SmartCard.kt: (36, 30): Unresolved reference: CardChannel
e: ~\util\SmartCard.kt: (44, 52): Unresolved reference: CardException
e: ~\util\SmartCard.kt: (51, 19): Unresolved reference: CardException
e: ~\util\SmartCard.kt: (54, 27): Unresolved reference: CommandAPDU

Also, I already looked classpath, and there is 'java.smartcardio' I attached a screenshot below.

classpath

What should I do?

ADD----------------

Wired thing is in Java code, it is working on same project. I think there is a problem with Kotllin environment settings.

2

There are 2 best solutions below

0
On BEST ANSWER

Here is an alternative way. I just give up using JDK's SmartCard classes since it was hard to use JDK one on JDK 11 version. Instead of it, I used a library from Github.

Here it is.

https://github.com/intarsys/smartcard-io

5
On

I think you need to include the java.smartcard module into the module in which the code that uses the unresolved classes you list is located. I created a small Kotlin project named kotlinsmartcard with the following code in the se.ivankrizsan package:

fun main() {
    val theCardTerminal: CardTerminal;
    println("Hello World!")
}

In the source root, that is not in any package, I have a file named module-info.java with the following contents:

module kotlinsmartcard {
    requires kotlin.stdlib;
    requires java.smartcardio;
}

I am able to run the above program using JDK 11.0.3-zulu (used this since I do not have the RedHat JDK at hand). This way my entire kotlinsmartcard project is one single module, in order to minimize the exposure to the Java module system, but I still need to have the "requires java.smartcardio" in order to not have an error at the variable declaration in the code.