ERROR:JDWP Unable to get JNI 1.2 environment ,jvm-> GetEvn() return =-2
Posted on 2008-04-13 23:01 Robert Su 閱讀(3986) 評(píng)論(7) 編輯 收藏ERROR:JDWP Unable to get JNI 1.2 environment ,jvm-> GetEvn() return =-2
原因:tomcat-eclipse-plugin插件啟動(dòng)報(bào)錯(cuò)
原因:JDK版本問(wèn)題
原因:tomcat-eclipse-plugin插件啟動(dòng)報(bào)錯(cuò)
ERROR:JDWP Unable to get JNI 1.2 environment ,jvm-> GetEvn() return =-2
原因:JDK版本問(wèn)題
查閱Java Doc,發(fā)現(xiàn)其中有這么一段話:
http://download.java.net/jdk6/docs/api/java/io/Console.html
"Whether a virtual machine has a console is dependent upon the underlying platform and also upon the manner in which the virtual machine is invoked. If the virtual machine is started from an interactive command line without redirecting the standard input and output streams then its console will exist and will typically be connected to the keyboard and display from which the virtual machine was launched. If the virtual machine is started automatically, for example by a background job scheduler, then it will typically not have a console." ">http://download.java.net/jdk6/docs/api/java/io/Con..."
翻譯一下:
虛
擬機(jī)是否有一個(gè)控制臺(tái)Console取決于所依賴的平臺(tái)和虛擬機(jī)解析該方法的方式。如果虛擬機(jī)是從一個(gè)交互式的命令行中啟動(dòng)的,而沒(méi)有重定向標(biāo)準(zhǔn)輸入和輸
出流,那么虛擬機(jī)會(huì)自動(dòng)的連接到鍵盤(pán)作為標(biāo)準(zhǔn)輸入,并且把啟動(dòng)虛擬機(jī)的地方作為標(biāo)準(zhǔn)輸出。如果虛擬機(jī)是自動(dòng)啟動(dòng)的,例如通過(guò)后臺(tái)的一個(gè)任務(wù)計(jì)劃,那么典型
的情況就是沒(méi)有Console控制臺(tái)......。
于是,思考一下我們運(yùn)行上面程序的地點(diǎn)——Eclipse等集成開(kāi)發(fā)環(huán)境,這對(duì)于上面描述中的把啟動(dòng)虛擬機(jī)的地方作為標(biāo)準(zhǔn)輸出來(lái)說(shuō)是不合適的,這里的Console()返回的默認(rèn)情況下是Null,于是就產(chǎn)生了上面的出錯(cuò)信息。(也許未來(lái)Eclipse會(huì)有所改進(jìn)吧)
怎么解決該問(wèn)題呢?這里提供兩條思路給大家(已經(jīng)實(shí)際操作過(guò),可以實(shí)現(xiàn)功能的正常運(yùn)作)
1、使用命令行進(jìn)行運(yùn)行,編譯可以使用集成開(kāi)發(fā)環(huán)境。這樣可以完成標(biāo)準(zhǔn)輸出。
2、在程序中重定向標(biāo)準(zhǔn)輸出到其他的設(shè)備或者方式(例如寫(xiě)到文本文件),這樣也可以"比較不方便的"完成該功能。