Browse Source

添加 setJavaAwtHeadless() 在缺少显示设备、键盘或鼠标时 Graphics、Font、Color、ImageIO 等等
API 仍然能够使用

James 5 years ago
parent
commit
9951818a14
1 changed files with 12 additions and 0 deletions
  1. 12 0
      src/main/java/com/jfinal/config/Constants.java

+ 12 - 0
src/main/java/com/jfinal/config/Constants.java

@@ -442,6 +442,18 @@ final public class Constants {
 	public ActionReporter getActionReporter() {
 		return actionReporter;
 	}
+	
+	/**
+	 * 设置 Headless Mode,以免在缺少显示设备时验证码功能不能使用,否则会抛出
+	 * java.awt.HeadlessException
+	 * 
+	 * Headless 模式是系统的一种配置模式。在该模式下,系统缺少显示设备、键盘或鼠标。
+	 * 配置为 "true" 时 Graphics、Font、Color、ImageIO、Print、Graphics2D
+	 * 等等 API 仍然能够使用
+	 */
+	public void setJavaAwtHeadless(boolean b) {
+		System.setProperty("java.awt.headless", b ? "true" : "false");
+	}
 }