java.lang.UnsatisfiedLinkError: Native Library attach.dll already loaded in another classloader
I was developing a plugin that using ExecutionListener
, Here are some of my code:
public class HotSwapExecutionListener implements ExecutionListener {
@Override
public void processStarted(@NotNull String executorId, @NotNull ExecutionEnvironment env,
@NotNull ProcessHandler handler) {
VirtualMachine vm = VirtualMachine.attach(pid); // error happens
// ....
targetVm.loadAgent("myagent.jar");
}
the code VirtualMachine vm = VirtualMachine.attach(pid)
throws an exception like below:
java.util.ServiceConfigurationError: com.sun.tools.attach.spi.AttachProvider: Provider sun.tools.attach.AttachProviderImpl could not be instantiated
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:581)
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:803)
at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:721)
at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1394)
at jdk.attach/com.sun.tools.attach.spi.AttachProvider.providers(AttachProvider.java:260)
at jdk.attach/com.sun.tools.attach.VirtualMachine.list(VirtualMachine.java:144)
at com.intellij.debugger.impl.attach.JavaDebuggerAttachUtil.attachVirtualMachine(JavaDebuggerAttachUtil.java:42)
at com.intellij.debugger.impl.attach.JavaAttachDebuggerProvider.getProcessAttachInfoInt(JavaAttachDebuggerProvider.java:231)
at com.intellij.debugger.impl.attach.JavaAttachDebuggerProvider.lambda$getProcessAttachInfo$1(JavaAttachDebuggerProvider.java:207)
at com.intellij.openapi.application.impl.ApplicationImpl$1.call(ApplicationImpl.java:268)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
Caused by: java.lang.UnsatisfiedLinkError: Native Library C:\Users\Administrator\.gradle\caches\modules-2\files-2.1\com.jetbrains\jbre\jbr-11_0_7-windows-x64-b944.20\jbr\bin\attach.dll already loaded in another classloader
at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2468)
at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2694)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2648)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:830)
at java.base/java.lang.System.loadLibrary(System.java:1870)
at jdk.attach/sun.tools.attach.AttachProviderImpl.<clinit>(AttachProviderImpl.java:175)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:779)
... 16 more
I copy the tools.jar file from my jdk installtion location(jdk8) to my plugin project and add it as dependency, so it should be in the classpath.
Can anyone tell me how to solve this issue?
really appreciate for your help!
here is my build.gradle.kts
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url = uri("https://plugins.gradle.org/m2/") }
maven { url = uri("https://oss.sonatype.org/content/repositories/releases/") }
maven { url = uri("https://dl.bintray.com/jetbrains/intellij-plugin-service") }
maven { url = uri("https://dl.bintray.com/jetbrains/intellij-third-party-dependencies/") }
}
dependencies {
classpath("org.jetbrains.intellij.plugins:gradle-intellij-plugin:0.7.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32")
}
}
plugins {
java
kotlin("jvm") version "1.4.32"
id("org.jetbrains.intellij") version "0.7.2"
}
java(Action {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
})
dependencies {
implementation(files("../libs/tools.jar"))
annotationProcessor("org.projectlombok:lombok:1.18.32")
}
IntelliJ IDEA 2023.3.2 (Ultimate Edition) Build #IU-233.13135.103, built on December 20, 2023
请先登录再写评论。
In your Gradle build please keep all tools and plugins up-to-date always.
e.g. id("org.jetbrains.intellij") version "0.7.2" is heavily outdated, update to latest version from https://github.com/JetBrains/intellij-platform-gradle-plugin/