1. steps:
Modify the $ catalina_home/bin/Catalina. Sh file ($ catalina_home refers to the tomcat installation directory). Add the following content to the 40 lines of the original file:
Catalina_opts = "-djava. AWT. Headless = true"
Save the disk and exit. It's easy :)))
2. test:
2.1 create a directory
CD/usr/local/tomcat/webapps/
Mkdir-P testimage/WEB-INF/classes
2.2 compile index. jsp
Create index. jsp in the/usr/local/tomcat/webapps/testimage directory. The content is as follows:
<% @ Page import = "Java. AWT. *, java. AWT. image. *, java. Io. *, com.sun.image.codec.jpeg. *" %>
<%
Bufferedimage Bi = new bufferedimage (200,100, bufferedimage. type_int_rgb );
Graphics G = Bi. getgraphics ();
G. drawstring ("test Java image", 0, 45 );
Fileoutputstream Fos = new fileoutputstream (application. getrealpath ("/") + "test.jpg ");
Required imageencoder required Ie = required codec. createJPEGEncoder (fos );
Using IE. encode (bi );
Fos. close ();
%>
2.3 run
Start tomcat, open the browser, and enter: http: // localhost: 8080/TestImage
3. Postscript
3.1Most of the solutions available on the Internet are to install xvfb, and then specify the default x server as xvfb. However, after using this method, the x window that comes with the system cannot be entered. It is very difficult to solve this additional problem. I have never been able to study it. If you know it, please reply below this document. Thank you.
3.2Some people have mentioned headless support, but it is always said that it is invalid to write headless support in the original java file, because tomcat is not started with Headless support. But why didn't they expect to add headless support during tomcat startup? Well, let's look at the 874 crowd.