日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

java.awt.headless 模式(Linux, java.awt.headless and the DISPLAY environment variable)

發(fā)布時間:2024/4/17 linux 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java.awt.headless 模式(Linux, java.awt.headless and the DISPLAY environment variable) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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. 測試程序:

  • import java.awt.Graphics;
  • import java.awt.image.BufferedImage;
  • import java.io.File;
  • import javax.imageio.ImageIO;

  • public class TestCHSGraphic{
  • ????
  • ????public static void main(String[] args) throws Exception{
  • ????????//設(shè)置Headless模式
  • ????????System.setProperty("java.awt.headless", "true");
  • ????????BufferedImage bi = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB);
  • ????????Graphics g = bi.getGraphics();
  • ????????String s = "Headless模式測試";
  • ????????g.drawString(new String(s.getBytes(), "GB2312"), 50, 50);
  • ????????ImageIO.write(bi, "jpeg", new File("test.jpg"));
  • ????}
  • ????
  • }
  • JDK1.4以上版本編譯運(yùn)行會在相同目錄下生成一幅圖片,如下:


    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

      • Install the required libXtst-devel and libXrender-devel RPM to the server per the instructions on our Confluence UNIX and X11 Dependencids page.
      • Check your DISPLAY environment variable and set the -Djava.awt.headless=true property in your JAVA_OPTS environment variable
      • Related Content

        {dynamiccontentbylabel:showLabels=false|showSpace=false}


        {kbsurvey}

        {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}

        與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

        總結(jié)

        以上是生活随笔為你收集整理的java.awt.headless 模式(Linux, java.awt.headless and the DISPLAY environment variable)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

        如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。