简体   繁体   English

oshi-core 中 SystemInfo class 的 NoClassDefFoundError

[英]NoClassDefFoundError for SystemInfo class in oshi-core

I have included oshi-core as a dependency in my project using Maven:我使用 Maven 将 oshi oshi-core作为依赖项包含在我的项目中:

Dependency Structure依赖结构

<dependencies>
    <dependency>
        <groupId>com.github.oshi</groupId>
        <artifactId>oshi-core</artifactId>
       <version>5.2.5</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>score-worker-monitor-api</artifactId>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
    </dependency>
</dependencies>

However, I am seeing this error:但是,我看到了这个错误:

2020-10-08 11:15:49,688 [scoreWorkerScheduler-5] (TaskUtils.java:95) ERROR - Unexpected error occurred in scheduled task.
java.lang.NoClassDefFoundError: oshi/SystemInfo
    at io.cloudslang.worker.monitor.CpuPerProcess.measure(CpuPerProcess.java:34)
    at io.cloudslang.worker.monitor.PerfMetricCollectorImpl.collectMetric(PerfMetricCollectorImpl.java:53)
    at io.cloudslang.worker.monitor.service.WorkerMetricCollectorServiceImpl.collectPerfMetrics(WorkerMetricCollectorServiceImpl.java:42)
    at sun.reflect.GeneratedMethodAccessor37.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748) 

I don't understand the below line from OSHI-GitHub.我不明白 OSHI-GitHub 的以下内容。 I mean having the dependency inside oshi-core then why should I add again jna dependencies?我的意思是在 oshi-core 中有依赖项,那我为什么要再次添加 jna 依赖项?

If you are using a parent (eg Spring Boot) that includes JNA as a dependency, override the jna.version property or equivalent如果您使用包含 JNA 作为依赖项的父项(例如 Spring Boot),请覆盖 jna.version 属性或等效属性

I am using a latest jna and jna-platform version inside oshi-core dependency.我在 oshi-core 依赖项中使用最新的 jna 和 jna-platform 版本。

The documentation on the OSHI website regarding a JNA NoClassDefFoundError is not relevant for this case, as it's OSHI itself that is not being found. OSHI 网站上关于 JNA NoClassDefFoundError的文档与这种情况无关,因为未找到 OSHI 本身。 The problem is in the package containing the first line of your stack trace:问题出在包含堆栈跟踪第一行的 package 中:

at io.cloudslang.worker.monitor.CpuPerProcess.measure(CpuPerProcess.java:34)

It appears from this package name you're using CloudSlang score , however, the latest version on GitHub does not include the class CpuPerProcess .从这个 package 名称看来,您正在使用CloudSlang 分数,但是,GitHub 上的最新版本不包括 class CpuPerProcess You may be working from a forked version of that repository.您可能正在使用该存储库的分叉版本。

In that case, you need to ensure the oshi-core dependency is included in the pom.xml for your forked version of CloudSlang.在这种情况下,您需要确保oshi-core依赖项包含在您的pom.xml分支版本的 pom.xml 中。

While it's not particularly relevant to the error you're seeing, to answer your question about JNA version is that it JNA artifacts are included within OSHI as a transitive dependency.虽然它与您看到的错误并不特别相关,但要回答您关于 JNA 版本的问题是 JNA 工件作为传递依赖项包含在 OSHI 中。 If you use the Spring starter parent (rather than just another dependency) then the Spring version of JNA takes precedence and you have to define this in your pom.xml to ensure Spring includes the correct version:如果您使用 Spring 起始父级(而不仅仅是另一个依赖项),那么 JNA 的 Spring 版本优先,您必须在pom.xml中定义它以确保 Spring 包含正确的版本:

<properties>
    <jna.version>5.6.0</jna.version>
</properties>

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

相关问题 Flink oshi-core 异常 - Flink oshi-core Exception 尝试使用OSHI的get()方法时引发NoClassDefFoundError - NoClassDefFoundError thrown when trying to use get() methods from OSHI 使用Proguard的Java核心类的NoClassDefFoundError - NoClassDefFoundError for java core class using Proguard NoClassDefFoundError 但有类 - NoClassDefFoundError but class is there jersey-core(UriComponent $ Type)提供的类上的NoClassDefFoundError - NoClassDefFoundError on a class provided by jersey-core (UriComponent$Type) java.lang.NoClassDefFoundError: 无法初始化 class com.google.inject.internal.cglib.core.$ReflectUtils - java.lang.NoClassDefFoundError: Could not initialize class com.google.inject.internal.cglib.core.$ReflectUtils java.lang.NoClassDefFoundError:无法初始化com.sun.jersey.core.header.MediaTypes类 - java.lang.NoClassDefFoundError: Could not initialize class com.sun.jersey.core.header.MediaTypes java.lang.NoClassDefFoundError:单元测试演示者类时com / google / gwt / core / client / GWTBridge异常 - java.lang.NoClassDefFoundError: com/google/gwt/core/client/GWTBridge exception while unit testing presenter class 线程“main”中的异常java.lang.NoClassDefFoundError:无法初始化类org.springframework.jdbc.core.StatementCreatorUtils - Exception in thread “main” java.lang.NoClassDefFoundError: Could not initialize class org.springframework.jdbc.core.StatementCreatorUtils 导入库Oshi - Import library Oshi
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM