Best way to detect whether code is running in an application server java

前端 未结 2 758
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 11:27

For a J2EE bean I am reusing code that was developed for a java swing application. JOptionPane.showMessageDialog() is unfortunately commonly used. Most occurenc

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-17 12:27

    Make sure the server is started with

    java -Djava.awt.headless=true
    

    Most servers should be started that way by default. Then you can check:

    boolean headless_check = GraphicsEnvironment.isHeadless();
    

    More details on headless available here:

提交回复
热议问题