Posted on 2008-04-13 23:01
Robert Su 閱讀(3984)
評論(7) 編輯 收藏
ERROR:
JDWP Unable to get JNI 1.2 environment ,jvm-> GetEvn() return =-2
原因:tomcat-eclipse-plugin插件啟動報錯
ERROR:JDWP Unable to get JNI 1.2 environment ,jvm-> GetEvn() return =-2
原因:JDK版本問題
查閱Java Doc,發現其中有這么一段話:
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..."
翻譯一下:
虛
擬機是否有一個控制臺Console取決于所依賴的平臺和虛擬機解析該方法的方式。如果虛擬機是從一個交互式的命令行中啟動的,而沒有重定向標準輸入和輸
出流,那么虛擬機會自動的連接到鍵盤作為標準輸入,并且把啟動虛擬機的地方作為標準輸出。如果虛擬機是自動啟動的,例如通過后臺的一個任務計劃,那么典型
的情況就是沒有Console控制臺......。
于是,思考一下我們運行上面程序的地點——Eclipse等集成開發環境,這對于上面描述中的把啟動虛擬機的地方作為標準輸出來說是不合適的,這里的Console()返回的默認情況下是Null,于是就產生了上面的出錯信息。(也許未來Eclipse會有所改進吧)
怎么解決該問題呢?這里提供兩條思路給大家(已經實際操作過,可以實現功能的正常運作)
1、使用命令行進行運行,編譯可以使用集成開發環境。這樣可以完成標準輸出。
2、在程序中重定向標準輸出到其他的設備或者方式(例如寫到文本文件),這樣也可以"比較不方便的"完成該功能。