---
title: "xhtmlrenderer在linux下无法使用"
author: "li2005"
date: "2012-08-30T13:27:52Z"
tags: []
categories: ["编程语言"]
slug: "xhtmlrenderer-linux"
draft: false
lastmod: "2012-08-30T13:27:52Z"
id: 1667810
url: "https://li2005.iteye.com/blog/1667810"
---

最近做了一个项目要生成pdf文件，用的是xhtmlrenderer+itext2.1.7，开发环境用的是windows xp + eclipse，开发好了后，自己在windows上测试没有一点问题，但进入系统测试后（用的linux），始终不能生成pdf文件，而且到处都没有throw exception，最后用remote debug连到服务器来测试程序，发现初始化xhtmlrenderer时下面一句代码不能正确执行

```java
GraphicsEnvironment gfx = GraphicsEnvironment.getLocalGraphicsEnvironment();
```

　　然后上网查资料，终于查到了
　　由于Linux环境下图形处理都需要X Server服务，如果Linux上没有安装图形模块，则没有X Server服务；另外一方面，即使有X Server服务，在Linux系统内存不够的时候，也会出现此错误。
　　解决方法就是在启动服务时加上这句参数　-Djava.awt.headless=true　就行了