5

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.

Pemassi
  • 612
  • 1
  • 7
  • 20
  • 1
    I don't know Kotlin, but "unresolved reference" sounds wrong. For a missing namespace the Java error is "package javax.smartcardio does not exist", with the fully-qualified package name. Your code is definitely right? It's probably also worth checking the contents of the javax.smartcardio.jar to make sure it does have the classes you're looking for. – Rup Sep 11 '19 at 06:05
  • I guess there is a problem with Kotlin when I code with Java it works, but Kotlin not. – Pemassi Sep 13 '19 at 07:39

2 Answers2

6

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.

  • 2
    Note that the module declaration I showed would in Java be located in a special file named module-info.java and thus have nothing to do with a dependency-management system like Maven or Gradle. –  Sep 11 '19 at 06:26
  • Is there another way to fix this problem? This way makes the code get errors everywhere. – Pemassi Sep 11 '19 at 07:29
  • I don't know why I did your solution but not working, so what I did is use java only for smartcardio. Then it's working.. Thank you! – Pemassi Sep 11 '19 at 08:07
  • I have an umodularized project. It doesn't find the package. – Jonathan Rosenne Dec 17 '19 at 17:14
  • not working for me, I'm using kotlin on jvm 1.8 – rmpt Mar 05 '23 at 17:17
1

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

Pemassi
  • 612
  • 1
  • 7
  • 20