java.awt.headless 模式(Linux, java.awt.headless and the DISPLAY environment variable)
http://blog.chinaunix.net/uid-25098298-id-287544.html
1. 什么是 java.awt.headless?
Headless模式是系統(tǒng)的一種配置模式。在該模式下,系統(tǒng)缺少了顯示設(shè)備、鍵盤或鼠標(biāo)。
2. 何時使用和headless mode?
Headless模式雖然不是我們愿意見到的,但事實(shí)上我們卻常常需要在該模式下工作,尤其是服務(wù)器端程序開發(fā)者。因為服務(wù)器(如提供Web服務(wù)的主機(jī))往往可能缺少前述設(shè)備,但又需要使用他們提供的功能,生成相應(yīng)的數(shù)據(jù),以提供給客戶端(如瀏覽器所在的配有相關(guān)的顯示設(shè)備、鍵盤和鼠標(biāo)的主機(jī))。
3. 如何使用和Headless mode?
一般是在程序開始激活headless模式,告訴程序,現(xiàn)在你要工作在Headless mode下,就不要指望硬件幫忙了,你得自力更生,依靠系統(tǒng)的計算能力模擬出這些特性來:
System.setProperty("java.awt.headless", "true");
4. 測試程序:
5. Toolkit類的getDefaultToolkit函數(shù)api中文說明
public static Toolkit getDefaultToolkit()獲取默認(rèn)工具包。如果名為 "java.awt.headless" 的系統(tǒng)屬性被設(shè)置為 true,則使用 Toolkit 的 headless 實(shí)現(xiàn)。如果不存在 "java.awt.headless" 或 "java.awt.headless" 被設(shè)置為 false,且存在名為 "awt.toolkit" 的系統(tǒng)屬性,則該屬性將被視為 Toolkit 子類的名稱;否則將使用特定于平臺的默認(rèn) Toolkit 實(shí)現(xiàn)。還可以使用 Sun 引用實(shí)現(xiàn)中指定的屬性 'assistive_technologies' 將其他類加載到 VM 中,該屬性是在 'accessibility.properties' 文件的一個行中指定的。形式是 "assistive_technologies=...",其中 "..." 是以逗號分隔的、要加載的輔助技術(shù)類的列表。每個類都以給定的順序加載,并且要使用 Class.forName(class).newInstance() 創(chuàng)建每個類的單獨(dú)實(shí)例。此操作在創(chuàng)建 AWT 工具包之后進(jìn)行。所有錯誤都通過 AWTError 異常來處理。 返回: 默認(rèn)工具包。 拋出: AWTError - 如果不能找到工具包,或者不能訪問或?qū)嵗ぞ甙?br />
參考: http://hi.baidu.com/lovemywolf/blog/item/be08ebed2293734979f05595.html
?? jdk api 文檔
博客推薦文章
- tomcat X connection to localhost:11.0 broken (2010-12-31 23:51:18)
- AIX上websphere6.1發(fā)布應(yīng)用程序后顯示中文亂碼問題 (2011-01-01 16:27:56)
- Robotium 只有apk測試 通過id獲取view (32分鐘前)
- JavaScript語句后應(yīng)該加分號么? (1小時前)
- jquery的uploadify上傳jsp+servlet (2小時前)
- =================
http://leshazlewood.com/2009/08/26/linux-javaawtheadless-and-the-display-environment-variable/
Just a quick note to self:
After looking at the JDK source code today, we found that even when setting -Djava.awt.headless=true, if a script executes with the DISPLAY environment variable set, the AWT graphics environment will still use a GraphicsEnvironment representing that DISPLAY.
A major problem with this is if the shell that launched the script that started the java process ever executes, the GraphicsEnvironment reflecting the DISPLAY will be removed and any Object instances reflecting that environment would be invalidated or Classes once available will no longer be available. resulting in a NoClassDefFoundException.
Bottom line: on Linux, if setting -Djava.awt.headless=true in a script, ensure that you unset DISPLAY in the script before starting the java process. It will save some headaches in debugging.
?
==============https://confluence.atlassian.com/plugins/viewsource/viewpagesrc.action?pageId=133693889
When attempting to use a Chart either with the Chart Plugin (JIRA 3.13) or the Pie Chart Gadget (4.0+), no output is rendered. Errors like the following appear in the logs:
| 2008-02-04 12:45:36,051 TP-Processor6 ERROR [500ErrorPage] Exception caught in 500 page /usr/local/java/jdk1.6.0_02/jre/lib/i386/xawt/libmawt.so: libXtst.so.6: cannot open shared object file: No such file or directory java.lang.UnsatisfiedLinkError: /usr/local/java/jdk1.6.0_02/jre/lib/i386/xawt/libmawt.so: libXtst.so.6: cannot open shared object file: No such file or directoryat java.lang.ClassLoader$NativeLibrary.load(Native Method)at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1647)at java.lang.Runtime.load0(Runtime.java:770)at java.lang.System.load(System.java:1005)at java.lang.ClassLoader$NativeLibrary.load(Native Method)at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1668)at java.lang.Runtime.loadLibrary0(Runtime.java:823)at java.lang.System.loadLibrary(System.java:1030)at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)at java.security.AccessController.doPrivileged(Native Method)at java.awt.Toolkit.loadLibraries(Toolkit.java:1594)at java.awt.Toolkit.<clinit>(Toolkit.java:1616)at java.awt.Color.<clinit>(Color.java:263)at com.atlassian.jira.ext.charting.jfreechart.ChartUtils.<clinit>(ChartUtils.java:45)at com.atlassian.jira.ext.charting.data.DataCollector.populatePieChart(DataCollector.java:669)at com.atlassian.jira.ext.charting.charts.singlefieldpie.SingleFieldPieChart.getViewHtml(SingleFieldPieChart.java:57)at com.atlassian.jira.ext.charting.charts.PortletSearchView.writeSearchResults(PortletSearchView.java:89) |
In addition, errors like the following appear:
| 2008-02-04 12:49:14,654 TP-Processor2 ERROR [webwork.dispatcher.ServletDispatcher] Could not execute action java.lang.NoClassDefFoundError: Could not initialize class com.atlassian.jira.ext.charting.jfreechart.ChartUtils at com.atlassian.jira.ext.charting.data.DataCollector.retrieveOrMakeSearchRequest(DataCollector.java:205) |
Cause
Charts that create custom graphics require X11 libraries and an X11 session to assist in creating their output.
Resolution
| |
Related Content
|
|
| {htmlcomment} Regular Expression: java.lang.NoClassDefFoundError: Could not initialize class com.atlassian.jira.ext.charting.jfreechart.ChartUtils http://support.atlassian.com/browse/JSP-19704 {htmlcomment} |
總結(jié)
以上是生活随笔為你收集整理的java.awt.headless 模式(Linux, java.awt.headless and the DISPLAY environment variable)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux DISPLAY作用
- 下一篇: linux 其他常用命令