putty上运行脚本调用java处理图形应用时报错

在putty上运行脚本并调用java程序,当java程序需要调用java图形界面时,可能会报如下错误:
java.lang.InternalError: Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable.
        at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
        at sun.awt.X11GraphicsEnvironment.access$000(X11GraphicsEnvironment.java:95)
        at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:184)
        at java.security.AccessController.doPrivileged(AccessController.java:192)
        at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:173)
        at java.lang.J9VMInternals.initializeImpl(Native Method)
        at java.lang.J9VMInternals.initialize(J9VMInternals.java:177)
        at java.lang.Class.forNameImpl(Native Method)
        at java.lang.Class.forName(Class.java:131)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:99)
        at net.sf.jasperreports.engine.util.JRGraphEnvInitializer.initializeGraphEnv(JRGraphEnvInitializer.java:58)
        at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:363)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:77)
        at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:59)
        at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:147)
        at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:83)
        at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)

可以在调用java main的脚本里添加如下参数:java.awt.headless=true
例如:java -Djava.awt.headless=true com.javaMain.class
这个参数含义是运行时,激活headless模式。
Headless模式是系统的一种配置模式。在该模式下,系统缺少了显示设备、键盘或鼠标。

一般是在程序开始激活headless模式,告诉程序,现在你要工作在Headless mode下,就不要指望硬件帮忙了,你得自力更生,依靠系统的计算能力模拟出这些特性来。

你可能感兴趣的:(Java AWT)