Browse Source

服务器启动好自动打开浏览器

pull/1/head
richie 4 years ago
parent
commit
6fab828534
  1. 13
      src/main/java/com/finebi/start/Learner.java

13
src/main/java/com/finebi/start/Learner.java

@ -1,12 +1,16 @@
package com.finebi.start;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ProductConstants;
import com.fr.startup.FineWebApplicationInitializer;
import com.fr.third.springframework.web.SpringServletContainerInitializer;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleState;
import org.apache.catalina.loader.WebappLoader;
import org.apache.catalina.startup.Tomcat;
import java.awt.*;
import java.net.URI;
import java.util.HashSet;
import java.util.Set;
@ -28,6 +32,15 @@ public class Learner {
String docBase = System.getProperty("user.dir") + "/" + APP_NAME;
ProductConstants.setWebAppName(ProductConstants.getAppFolderName());
String appName = "/" + APP_NAME;
tomcat.getServer().addLifecycleListener(lifecycleEvent -> {
if (LifecycleState.STARTED.equals(lifecycleEvent.getLifecycle().getState())) {
try {
Desktop.getDesktop().browse(new URI("http://localhost:8080/webroot/decision"));
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
});
Context context = tomcat.addContext(appName, docBase);
Tomcat.initWebappDefaults(context);

Loading…
Cancel
Save