我使用 Maven 在我的项目中包含oshi-core
了一个依赖项:
依赖结构
<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>
但是,我看到了这个错误:
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)
我不明白 OSHI-GitHub 的以下行。我的意思是在 oshi-core 中有依赖项,那么我为什么要再次添加 jna 依赖项?
如果您使用包含 JNA 作为依赖项的父级(例如 Spring Boot),请覆盖 jna.version 属性或等效项
我在 oshi-core 依赖项中使用了最新的 jna 和 jna-platform 版本。