When you build a project with spring boot, you want to automatically talk about first pages after the project starts.
I used the Java.awt.Desktop class.
if ( Desktop.isdesktopsupported ()) { try { // Pop-up browser - show http interface (HTTPS) desktop.getdesktop (). Browse (New uri ("81383628")); } catch (exception e) { logger.info (E.getMessage ()); } }
The results are normally accessed in the test class and cannot be ejected 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<void>) () -> { 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 ( &Nbsp; 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 (). IsEmpty ()); } } } else { headless = boolean.valueof (NM); } return null; }); } return headless; }
To troubleshoot the cause, it is found that System.getproperty ("java.awt.headless") in the Getheadlessproperty method returns True when the system parameter is obtained.
Causes the headlessexception exception to be thrown directly. Headless mode is a system configuration in the absence of a display, keyboard, or mouse, which causes the specified window to not pop up.
System.setproperty ("Java.awt.headless", "false");
So you need to set the parameter to False in advance.
Java AWT Desktop cannot invoke the system browser