亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

VirtualMachine.attach(pid) 失敗并出現 java.io.

VirtualMachine.attach(pid) 失敗并出現 java.io.

幕布斯6054654 2023-02-23 16:34:14
在經歷了這個討論之后,我相信附加到同一個 VM 的選項默認情況下在 OpenJDK11 中已被禁用。我正在嘗試將 Java 代理升級到 OpenJDK11,在調用時的測試用例中,VirtualMachine.attach(pid)我看到它失敗并出現以下錯誤。處理這種情況的正確方法是什么?完整的堆棧跟蹤:java.io.IOException: Can not attach to current VMat jdk.attach/sun.tools.attach.HotSpotVirtualMachine.<init>(HotSpotVirtualMachine.java:75)at jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:48)at jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:69)at jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)at org.kantega.notsoserial.WithAgentIT.attachAgent(WithAgentIT.java:76)at org.kantega.notsoserial.WithAgentIT.attackShouldBePreventedWithAgent(WithAgentIT.java:47)at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.base/java.lang.reflect.Method.invoke(Method.java:566)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
查看完整描述

4 回答

?
慕虎7371278

TA貢獻1802條經驗 獲得超4個贊

請參閱JDK-8180425:發行說明:默認情況下無法使用附加 API 附加到當前 VM

Attach API 的實現在 JDK 9 中已更改為默認情況下不允許附加到當前 VM。此更改對使用 Attach API 附加到正在運行的 VM 的工具應該沒有影響。它可能會影響濫用此 API 作為獲取java.lang.instrumentAPI 的方式的庫。jdk.attach.allowAttachSelf可以在命令行上設置系統屬性以減輕與此更改的任何兼容性。


查看完整回答
反對 回復 2023-02-23
?
一只斗牛犬

TA貢獻1784條經驗 獲得超2個贊

我不確定這是否對每個人都有幫助,但就我而言,這是一個測試用例,用于測試代理是否正確附加到 JDK(當代理實際附加到 JDK 時它不會自附加,即,實際運行時不是測試用例)。


根據@Holger 的建議,在評論中,我修改了我的 maven-failsafe-plugin 以允許自我附加。


        <plugin>

            <artifactId>maven-failsafe-plugin</artifactId>

            <version>2.22.2</version>

            <executions>

                <execution>

                    <goals>

                        <goal>integration-test</goal>

                        <goal>verify</goal>

                    </goals>

                    <configuration>

                        <argLine>-Djdk.attach.allowAttachSelf=true</argLine>

                        <forkMode>once</forkMode>

                    </configuration>

                </execution>

            </executions>

        </plugin>


查看完整回答
反對 回復 2023-02-23
?
狐的傳說

TA貢獻1804條經驗 獲得超3個贊

使用 JVM 參數:-Djdk.attach.allowAttachSelf=true

你可以解決它。


查看完整回答
反對 回復 2023-02-23
?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

這通過在 maven-surefire-plugin 中添加 javaagent 對我有用


<plugin>

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-surefire-plugin</artifactId>

        <version>${maven-surefire-plugin.version}</version>

        <configuration>

          <!-- Centralize test reports in parent project -->

          <reportsDirectory>${basedir}/../target/surefire-reports</reportsDirectory>

          <!-- Sets the VM argument line used for Jacoco when unit tests are run. -->

          <argLine>

             -javaagent:${settings.localRepository}/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar ${surefireArgLine}

          </argLine>

        </configuration> 

</plugin>


查看完整回答
反對 回復 2023-02-23
  • 4 回答
  • 0 關注
  • 519 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號