Porting a Java app that uses AWT and Swing for drawing movies to the server-side

狂风中的少年 提交于 2019-11-26 10:03:35

问题


I am working with some code that writes animated output to the desktop using AWT and Swing features. It draws using 2D graphics and renders text in fonts.

This code can use the Java Media Framework to save the animationto movie files.

I would like to port this code to a pure server-side environment, for working with a Web UI. The drawing code could either run inside the servlet container, or outside as a command-line program. (Or I could opt not to use a servlet container and instead use the newer ways of running Java web servers from the command line.)

Can I use AWT and Swing drawing features without starting the X Window System on the server?


回答1:


The article Using Headless Mode in the Java SE Platform outlines the limitations imposed on such applications.

As a concrete example JFreeChart is a graphic program widely used in both desktop and servlet contexts. For the latter, any of several ChartUtilities may be used to stream rendered content in a headless environment.

Alternatively, consider Java Web Start to deploy an existing Swing application, for example the JFreeChart demo seen here.

Addendum: This Oracle forum thread suggests that the Java Media Framework can indeed throw HeadlessException; a suggested workaround is to specify a particular system property value:

-Dawt.toolkit=sun.awt.HeadlessToolkit

This JFreeChart forum thread suggests Xvfb or vnc as alternatives when headless mode is not available.



来源:https://stackoverflow.com/questions/13984381/porting-a-java-app-that-uses-awt-and-swing-for-drawing-movies-to-the-server-side

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!