In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
When building a project with Spring boot, I hope to automatically talk about the home page after the project is started.
I used the java.awt.Desktop class.
If (Desktop.isDesktopSupported ()) {try {/ / pop-up browser-displays the HTTP interface (https) Desktop.getDesktop () .browse (new URI ("https://blog.csdn.net/weixin_42156742/article/details/81383628"));} catch (Exception e) {LOGGER.info (e.getMessage () }}
As a result, it can be accessed normally in the test class, but the web page cannot be popped up after starting the project.
Public static synchronized Desktop getDesktop () {if (GraphicsEnvironment.isHeadless ()) throw new HeadlessException (); if (! Desktop.isDesktopSupported ()) {throw new UnsupportedOperationException ("Desktop API is not" + "supported on the current platform");} sun.awt.AppContext context = sun.awt.AppContext.getAppContext () Desktop desktop = (Desktop) context.get (Desktop.class); if (desktop = = null) {desktop = new Desktop (); context.put (Desktop.class, desktop);} return desktop } private static boolean getHeadlessProperty () {if (headless = = null) {AccessController.doPrivileged ((PrivilegedAction) ()-> {String nm = System.getProperty ("java.awt.headless") If (nm = null) {/ * No need to ask for DISPLAY when run in a browser * / if (System.getProperty ("javaplugin.version")! = null) {headless = defaultHeadless = Boolean.FALSE;} else {String osName = System.getProperty ("os.name") If (osName.contains ("OS X") & & "sun.awt.HToolkit" .equals (System.getProperty ("awt.toolkit")) {headless = defaultHeadless = Boolean.TRUE } else {final String display = System.getenv ("DISPLAY") Headless = defaultHeadless = ("Linux" .equals (osName) | | "SunOS" .equals (osName) | | "FreeBSD" .equals (osName) | | "NetBSD" .equals (osName) | | "OpenBSD" .equals (osName) | | "AIX" .equals (osName) & & (display = = null | | display.trim () .equals ()) } else {headless = Boolean.valueOf (nm);} return null;});} return headless;}
Dig down and find that true is returned when the system parameter is obtained at System.getProperty ("java.awt.headless") in the getHeadlessProperty method.
Causes a HeadlessException exception to be thrown directly. Headless mode is the system configuration when the display, keyboard, or mouse is missing, which is because the parameters here prevent the specified window from popping up.
System.setProperty ("java.awt.headless", "false")
So you need to set the parameter to false in advance.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.