JAVA 遠程debug

來源:互聯網
上載者:User

開啟JVM的遠程Debug模式, 在啟動JVM的時候加上參數:

// 非阻塞方式,這樣啟動jvm後,可以再任意時間attach到server上-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=11312,server=y,suspend=n// 阻塞debug,啟動JVM後,需要遠端連線attach到相應的連接埠,JVM才會繼續執行。-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=11312,server=y,suspend=y

第二條特別適合調試類初始化的程式模組。

在eclipse中,bug項裡有Debug Configurations... 選中。然後選中remove java application, 建立一個

Project就是你要遠端偵錯的 JAVA源碼檔案工程。  HOST就是那個server所在的機器名或者IP。 PORT就是 上面的address項11312。Connection Type就寫Standard. 然後點擊debug就可以。 

如果debug後,有串連錯誤。 1. 要查看server或者service是否已經啟動。 2. 要看是否配置正確。3.檢測連接埠是否被其他程式佔用了。

如果上面的檢測完畢,還是串連失敗。那麼重啟eclipse 或者 重啟server. 這兩個方法就可以解決問題。

另外

-Xnoagent
這一個選項在遠程debug中一般不需要。其含義為Disables VM support for oldjdb。禁用舊的java debug。

下面是各個options的詳解。摘自http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/jdb.html

-Xdebug Enables debugging support in the VM
-Xrunjdwp:transport=dt_shmem,server=y,suspend=n Loads in-process debugging libraries and specifies the kind of connection to be made.
-Xnoagent Disables VM support for oldjdb
-Djava.compiler=NONE Disables the JIT compiler. This is required for debugging under the classic VM

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.