how to set jdk.attach.allowAttachSelf=true globally

孤者浪人 提交于 2020-05-10 03:07:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!