问题
I am trying to move one of our systems from java 8 to java 9 and about one third of the unit tests that worked OK in java 8 fails with the error below:
java.io.IOException: Can not attach to current VM
Google took me to a few pages and I quickly understood that in java 9 the default behavior was changed to prevent attaching to the current VM and to go back to the old way you need to set the system property jdk.attach.allowAttachSelf
to true.
When setting this in IntelliJ the tests work fine. The same works when changing build.gradle to include this:
test {
jvmArgs '-Djdk.attach.allowAttachSelf=true'
}
However, I would rather prefer to have this setting globally so I don't need to hack my build.gradle and IntelliJ.
I am running java 9 on ubuntu and I changed /etc/profile.d/jdk.sh
to include this:
export JDK_JAVA_OPTIONS="-Djdk.attach.allowAttachSelf=true"
When running my Gradle build I can see the setting being picked up because I am getting below in the build output:
NOTE: Picked up JDK_JAVA_OPTIONS: -Djdk.attach.allowAttachSelf=true
However, the tests keep failing with the same IOException.
So what I am doing wrong and how should I fix it?
Thank you in advance for your inputs.
来源:https://stackoverflow.com/questions/50498102/how-to-set-jdk-attach-allowattachself-true-globally