【问题标题】:Kotlin use of JDK modulesKotlin 使用 JDK 模块
【发布时间】:2018-12-20 09:26:27
【问题描述】:

我目前正在编写使用 javax.smartcardio lib 的 Java 库(由我开发)的 Kotlin 代码,但在 Kotlin 编译时显示以下错误:

Cannot access class 'javax.smartcardio.CommandAPDU'. Check your module classpath for missing or conflicting dependencies

我能做些什么来解决这个问题?

谢谢。

编辑:我正在使用 maven,我的依赖项和插件如下:

<properties>
    <kotlin.version>1.3.11</kotlin.version>
</properties>


<dependencies>
    <dependency>
        <groupId>io.javalin</groupId>
        <artifactId>javalin</artifactId>
        <version>2.4.0</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.25</version>
    </dependency>

    <!-- Kotlin -->
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib-jdk8</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-test</artifactId>
        <version>${kotlin.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-reflect</artifactId>
        <version>${kotlin.version}</version>
    </dependency>

    <dependency>
        <groupId>my.project</groupId>
        <artifactId>apdu-processor</artifactId>
        <version>0.1-SNAPSHOT</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <version>${kotlin.version}</version>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>test-compile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <jvmTarget>1.8</jvmTarget>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>testCompile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

使用javax.smartcardio 的库是apdu-processor。

【问题讨论】:

  • 您可能需要提供更多信息,例如您如何设置依赖项(例如,您使用过 Gradle 还是 Maven,构建脚本是什么样的,等等)
  • 现在看看。如果缺少任何其他信息或/和需要任何其他信息,请告知。
  • 哪些依赖项应该引入导致问题的类,即'javax.smartcardio.CommandAPDU?
  • apdu-processor,这是我的图书馆。
  • 他问的是javax.smartcardio.CommandAPDU类位于哪个库中,而不是哪个库正在使用它。

标签: java kotlin smartcardio


【解决方案1】:

由于javax.smartcardio 不是您项目的直接依赖项,因此需要从apdu-processor 传递声明。您必须确保此依赖项声明为 COMPILE 依赖项,而不是 PROVIDED,也不是 RUNTIME。

您始终可以通过在项目中明确声明 hte 依赖项来修复它。

【讨论】:

  • apdu-processor 在其pom.xml 中不包含依赖项。相反,它使用--add-modules javax.smartcardio Java 标志来添加它。因此,此解决方案不起作用。
猜你喜欢
  • 2022-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-18
  • 2022-10-21
  • 2018-03-19
  • 1970-01-01
相关资源
最近更新 更多