Eclipse下使用Runtime.getRuntime().exec啟動ja

來源:互聯網
上載者:User

標籤:blog   http   io   使用   java   ar   art   代碼   sp   

window7系統下實驗(linux下路徑格式和windows下不一樣) Eclipse下使用Runtime.getRuntime().exec啟動ja

RunTime.getRuntime().exec("java My_Program");System.exit(0); which would start a whole new JVM running your program, and then kill the original. Not exactly pretty or efficient, but it would restart it.

 今天在Eclipse中寫了用到 Runtime.getRuntime().exec("java MyTest"); 來啟動一個新的java程式,無奈卻無法啟動MyTest類。

1.  而這個程式在cmd中是可以完全正常啟動並執行。於是我將MyTest.class(除去包名)複製到此工程的根目錄下,突然發現MyTest程式啟動

了!

   我由此得出結論,使用Runtime.getRuntime().exec來啟動其他java程式時,  java虛擬機器是在工程的根目錄下開始尋找這個類的,而這個類實際存在於bin目錄下面。這時只要在命令中加入classpath的設定資訊皆可,另外需加上包名。

最後修改代碼如下:

2. Runtime.getRuntime().exec("java -classpath H:\\workspace\\javawork\\bin   cn.itcast.io.MyTest");

或者

3.Runtime.getRuntime().exec("java -classpath ./bin   cn.itcast.io.MyTest");  .代表目前的目錄.

或者

4.Runtime.getRuntime().exec("java -classpath bin   cn.itcast.io.MyTest");

程式正常運行!

原文:http://blog.sina.com.cn/s/blog_6b96eae10100ok01.html

Eclipse下使用Runtime.getRuntime().exec啟動ja

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.