From ddc6c6d3a68f0be88630073e2396e72be82f4895 Mon Sep 17 00:00:00 2001 From: ju Date: Wed, 6 Jun 2018 11:06:35 +0800 Subject: [PATCH] =?UTF-8?q?CORE-76=20Activator=E9=87=8D=E5=A4=8D=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=86=85=E7=BD=AE=E6=9C=8D=E5=8A=A1=E5=99=A8=E3=80=81?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E7=8E=AF=E5=A2=83=E7=9A=84=E6=94=AF=E6=8C=81?= =?UTF-8?q?=201=E3=80=81=E9=87=8D=E5=86=99=E4=B8=80=E4=B8=8B=E4=B9=8B?= =?UTF-8?q?=E5=89=8D=E7=9A=84=E5=86=85=E7=BD=AEtomcat=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=EF=BC=8C=E7=9B=B4=E6=8E=A5=E6=8C=87=E5=AE=9Ainitializer?= =?UTF-8?q?=EF=BC=8C=E7=9C=81=E7=9A=84tomcat=E4=B9=9F=E8=A6=81=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E4=B8=80=E9=81=8Dclass=202=E3=80=81tomcat=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E6=97=B6=EF=BC=8C=E5=85=B3=E9=97=ADactivator=20?= =?UTF-8?q?=E8=BF=98=E6=9C=89=E4=B8=80=E4=BA=9B=E5=BE=85=E5=AE=8C=E5=96=84?= =?UTF-8?q?=EF=BC=8C=E6=97=A0=E9=98=BB=E5=A1=9E=EF=BC=8C=E5=85=88=E4=BC=A0?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=96=B9=E4=BE=BF=E5=90=84=E4=B8=AA=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E7=9A=84Activator=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/design/DesignerEnvManager.java | 2 +- .../design/actions/file/PreferencePane.java | 2 +- .../fr/design/actions/help/WebDemoAction.java | 4 +- .../src/com/fr/design/utils/DesignUtils.java | 15 +- .../com/fr/start/BBSGuestPaneProvider.java | 2 +- .../{StartServer.java => ServerStarter.java} | 154 +++------- .../src/com/fr/start/TomcatFRHost.java | 56 ---- .../com/fr/start/server/EmbedServerEvent.java | 15 + .../src/com/fr/start/server/FRTomcat.java | 133 --------- .../com/fr/start/server/FineEmbedServer.java | 119 ++++++++ .../fr/start/server/MultiOutputStream.java | 62 ---- .../fr/start/server/ServerManageFrame.java | 76 ++--- .../src/com/fr/start/server/ServerTray.java | 171 ++++------- .../src/com/fr/start/server/TomcatHost.java | 280 ------------------ .../fr/start/server/TomcatServerListener.java | 18 -- .../map/server/ChartMapEditorAction.java | 6 +- .../src/com/fr/start/Designer.java | 5 +- .../fr/start/module/DesignerEnvProvider.java | 4 +- 18 files changed, 288 insertions(+), 836 deletions(-) rename designer-base/src/com/fr/start/{StartServer.java => ServerStarter.java} (59%) delete mode 100644 designer-base/src/com/fr/start/TomcatFRHost.java create mode 100644 designer-base/src/com/fr/start/server/EmbedServerEvent.java delete mode 100644 designer-base/src/com/fr/start/server/FRTomcat.java create mode 100644 designer-base/src/com/fr/start/server/FineEmbedServer.java delete mode 100644 designer-base/src/com/fr/start/server/MultiOutputStream.java delete mode 100644 designer-base/src/com/fr/start/server/TomcatHost.java delete mode 100644 designer-base/src/com/fr/start/server/TomcatServerListener.java diff --git a/designer-base/src/com/fr/design/DesignerEnvManager.java b/designer-base/src/com/fr/design/DesignerEnvManager.java index 209de7c6e..998c241e0 100644 --- a/designer-base/src/com/fr/design/DesignerEnvManager.java +++ b/designer-base/src/com/fr/design/DesignerEnvManager.java @@ -740,7 +740,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { /** * 返回Jetty服务器的端口号 */ - public int getJettyServerPort() { + public int getInnerServerPort() { return this.jettyServerPort; } diff --git a/designer-base/src/com/fr/design/actions/file/PreferencePane.java b/designer-base/src/com/fr/design/actions/file/PreferencePane.java index fd9024293..3ba725252 100644 --- a/designer-base/src/com/fr/design/actions/file/PreferencePane.java +++ b/designer-base/src/com/fr/design/actions/file/PreferencePane.java @@ -550,7 +550,7 @@ public class PreferencePane extends BasicPane { this.pageLengthComboBox.setSelectedIndex(designerEnvManager.getPageLengthUnit()); this.reportLengthComboBox.setSelectedIndex(designerEnvManager.getReportLengthUnit()); - this.portEditor.setValue(new Integer(designerEnvManager.getJettyServerPort())); + this.portEditor.setValue(new Integer(designerEnvManager.getInnerServerPort())); this.jdkHomeTextField.setText(designerEnvManager.getJdkHome()); diff --git a/designer-base/src/com/fr/design/actions/help/WebDemoAction.java b/designer-base/src/com/fr/design/actions/help/WebDemoAction.java index bf3f65229..2532d0b0d 100644 --- a/designer-base/src/com/fr/design/actions/help/WebDemoAction.java +++ b/designer-base/src/com/fr/design/actions/help/WebDemoAction.java @@ -4,7 +4,7 @@ import com.fr.base.BaseUtils; import com.fr.design.actions.UpdateAction; import com.fr.design.menu.MenuKeySet; import com.fr.general.Inter; -import com.fr.start.StartServer; +import com.fr.start.ServerStarter; import javax.swing.*; import java.awt.event.ActionEvent; @@ -23,7 +23,7 @@ public class WebDemoAction extends UpdateAction { * @param evt 事件 */ public void actionPerformed(ActionEvent evt) { - StartServer.browserDemoURL(); + ServerStarter.browserDemoURL(); } public static final MenuKeySet PRODUCT_DEMO = new MenuKeySet() { diff --git a/designer-base/src/com/fr/design/utils/DesignUtils.java b/designer-base/src/com/fr/design/utils/DesignUtils.java index 1148d64f4..7429535a0 100644 --- a/designer-base/src/com/fr/design/utils/DesignUtils.java +++ b/designer-base/src/com/fr/design/utils/DesignUtils.java @@ -9,7 +9,6 @@ import com.fr.base.ServerConfig; import com.fr.base.Utils; import com.fr.base.remote.RemoteDeziConstants; import com.fr.dav.DavXMLUtils; -import com.fr.dav.LocalEnv; import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; import com.fr.design.fun.DesignerEnvProcessor; @@ -29,7 +28,7 @@ import com.fr.stable.CodeUtils; import com.fr.stable.EncodeConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; -import com.fr.start.StartServer; +import com.fr.start.ServerStarter; import javax.swing.*; import java.awt.*; @@ -142,7 +141,7 @@ public class DesignUtils { String line = null; while ((line = reader.readLine()) != null) { if (line.startsWith("demo")) { - StartServer.browserDemoURL(); + ServerStarter.browserDemoURL(); } else if (StringUtils.isNotEmpty(line)) { File f = new File(line); String path = f.getAbsolutePath(); @@ -208,15 +207,9 @@ public class DesignUtils { break; } } - // 更新CurrentEnv于FRContext & DesignerEnvManager FRContext.setCurrentEnv(env); - refreshDesignerFrame(env); - // 当换了运行环境,重置服务器,让它下次预览时重启 - if (env instanceof LocalEnv && !ComparatorUtils.equals(env.getPath(), oldEnvPath)) { - StartServer.currentEnvChanged(); - } } public static void refreshDesignerFrame(Env env) { @@ -358,10 +351,10 @@ public class DesignUtils { } else { try { String web = GeneralContext.getCurrentAppNameOfEnv(); - String url = "http://localhost:" + DesignerEnvManager.getEnvManager().getJettyServerPort() + String url = "http://localhost:" + DesignerEnvManager.getEnvManager().getInnerServerPort() + "/" + web + "/" + ServerConfig.getInstance().getServletName() + baseRoute + postfixOfUri; - StartServer.browserURLWithLocalEnv(url); + ServerStarter.browserURLWithLocalEnv(url); } catch (Throwable e) { // } diff --git a/designer-base/src/com/fr/start/BBSGuestPaneProvider.java b/designer-base/src/com/fr/start/BBSGuestPaneProvider.java index eb094ca71..cc664b1ca 100644 --- a/designer-base/src/com/fr/start/BBSGuestPaneProvider.java +++ b/designer-base/src/com/fr/start/BBSGuestPaneProvider.java @@ -10,6 +10,6 @@ package com.fr.start; */ public interface BBSGuestPaneProvider { - public static final String XML_TAG = "BBSGuestPane"; + String XML_TAG = "BBSGuestPane"; } \ No newline at end of file diff --git a/designer-base/src/com/fr/start/StartServer.java b/designer-base/src/com/fr/start/ServerStarter.java similarity index 59% rename from designer-base/src/com/fr/start/StartServer.java rename to designer-base/src/com/fr/start/ServerStarter.java index 7ab65e549..01d16b98d 100644 --- a/designer-base/src/com/fr/start/StartServer.java +++ b/designer-base/src/com/fr/start/ServerStarter.java @@ -16,57 +16,43 @@ import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; import com.fr.general.Inter; import com.fr.log.FineLoggerFactory; -import com.fr.stable.EnvChangedListener; import com.fr.stable.OperatingSystem; import com.fr.stable.ProductConstants; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; -import com.fr.start.server.TomcatHost; +import com.fr.start.server.FineEmbedServer; -import javax.swing.BorderFactory; -import javax.swing.JOptionPane; -import java.awt.BorderLayout; -import java.awt.Desktop; -import java.awt.Font; +import javax.swing.*; +import java.awt.*; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -public class StartServer { - public static boolean NEED_LOAD_ENV = true; - // 原先的tomcatHost放在类TomcatHost里面,很不方便操作,而且因为存在多个进程的原因, - // 原先的getInstance()方法无多大意义 - private static TomcatHost tomcatHost = null; - private static Object lock = new Object(); - - static { - GeneralContext.addEnvChangedListener(new EnvChangedListener() { - public void envChanged() { - currentEnvChanged(); - } - }); - } - +public class ServerStarter { + /** * 预览Demo * 找默认工作目录,不应该按照名字去找,而应该按照安装路径,因为默认工作目录的名字可能会改变。 */ public static void browserDemoURL() { + if (FRContext.getCurrentEnv() instanceof RemoteEnv) { browser(FRContext.getCurrentEnv().getPath()); return; } if (ComparatorUtils.equals(StableUtils.getInstallHome(), ".")) {//august:供代码使用 String web = GeneralContext.getCurrentAppNameOfEnv(); - browserURLWithLocalEnv("http://localhost:" + DesignerEnvManager.getEnvManager().getJettyServerPort() + "/" + web + "/" + ServerConfig.getInstance().getServletName()); + browserURLWithLocalEnv("http://localhost:" + DesignerEnvManager.getEnvManager().getInnerServerPort() + "/" + web + "/" + ServerConfig.getInstance().getServletName()); return; } DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); if (!envManager.isCurrentEnvDefault()) { InformationPane inf = new InformationPane(envManager.getDefaultEnvName()); inf.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + @Override public void doOk() { + try { SignIn.signIn(DesignerEnvManager.getEnvManager().getDefaultEnv()); TemplateTreePane.getInstance().refreshDockingView(); @@ -76,99 +62,43 @@ public class StartServer { } initDemoServerAndBrowser(); } - + }).setVisible(true); } else { initDemoServerAndBrowser(); } } - + private static void initDemoServerAndBrowser() { - synchronized (lock) { - if (tomcatHost != null) { - if (!tomcatHost.isDemoAppLoaded()) { - tomcatHost.exit(); - tomcatHost = new TomcatHost(DesignerEnvManager.getEnvManager().getJettyServerPort()); - tomcatHost.addAndStartInstallHomeWebApp(); - } - } else { - tomcatHost = new TomcatHost(DesignerEnvManager.getEnvManager().getJettyServerPort()); - tomcatHost.addAndStartInstallHomeWebApp(); - } - } + try { - if (!tomcatHost.isStarted()) { - tomcatHost.start(); - } - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage()); + FineEmbedServer.getInstance().start(); } finally { //先访问Demo, 后访问报表, 不需要重置服务器. - NEED_LOAD_ENV = false; - browser("http://localhost:" + DesignerEnvManager.getEnvManager().getJettyServerPort() + "/" + GeneralContext.getCurrentAppNameOfEnv() + "/" + ServerConfig.getInstance().getServletName()); - } - } - - public static void start() { - try { - synchronized (lock) { - if (tomcatHost != null) { - if (NEED_LOAD_ENV) { - tomcatHost.exit(); - tomcatHost = new TomcatHost(DesignerEnvManager.getEnvManager().getJettyServerPort()); - tomcatHost.addAndStartLocalEnvHomeWebApp(); - - } - } else { - tomcatHost = new TomcatHost(DesignerEnvManager.getEnvManager().getJettyServerPort()); - tomcatHost.addAndStartLocalEnvHomeWebApp(); - - } - if (!tomcatHost.isStarted()) { - tomcatHost.start(); - } - } - } catch (InterruptedException e) { - FineLoggerFactory.getLogger().error(e.getMessage()); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage()); - } finally { - NEED_LOAD_ENV = false; + browser("http://localhost:" + DesignerEnvManager.getEnvManager().getInnerServerPort() + "/" + GeneralContext.getCurrentAppNameOfEnv() + "/" + ServerConfig.getInstance().getServletName()); } } - + /** * 本地环境浏览url * * @param url 指定路径 */ public static void browserURLWithLocalEnv(String url) { - start(); + + FineEmbedServer.getInstance().start(); browser(url); } - - public static TomcatHost getInstance() { - // august: 正确的逻辑能保证jettyHost不为null,不然就有bug,不允许这儿加是否等于null判断 - return tomcatHost; - } - - /** - * 运行环境改变事件 - */ - public static void currentEnvChanged() { - if (!NEED_LOAD_ENV) { - NEED_LOAD_ENV = true; - } - } - + private static void browser(String uri) { + if (StringUtils.isEmpty(uri)) { FRContext.getLogger().info("The URL is empty!"); return; } try { Desktop.getDesktop().browse(new URI(uri)); - + } catch (IOException e) { startBrowserFromCommand(uri, e); } catch (URISyntaxException e) { @@ -178,8 +108,9 @@ public class StartServer { FineLoggerFactory.getLogger().error("Can not open the browser for URL: " + uri); } } - + private static void startBrowserFromCommand(String uri, IOException e) { + if (OperatingSystem.isWindows()) { try { // win10 内存用到到80%左右的时候, Desktop.browser经常提示"存储空间不足, 无法处理改命令", 用rundll32可以打开. @@ -192,30 +123,40 @@ public class StartServer { FineLoggerFactory.getLogger().error(e.getMessage(), e); } } - + + public static boolean isStarted() { + + return FineEmbedServer.getInstance().isRunning(); + } + private static class InformationPane extends BasicPane { + private static final long serialVersionUID = 1L; + private static final int FREE_STYLE_TOP = 15; + private static final int FREE_STYLE_OTHER = 5; - - public InformationPane(String message) { + + InformationPane(String message) { + init(message); } - + private void init(String message) { + this.setLayout(new BorderLayout(10, 10)); this.setBorder(BorderFactory.createEmptyBorder(FREE_STYLE_TOP, FREE_STYLE_OTHER, FREE_STYLE_OTHER, FREE_STYLE_OTHER)); String text; if (!ComparatorUtils.equals(message, Inter.getLocText(new String[]{"Default", "Utils-Report_Runtime_Env"}))) { - text = new StringBuffer(Inter.getLocText("FR-Designer_Open")) - .append(ProductConstants.APP_NAME) - .append(Inter.getLocText("FR-Designer_Utils-OpenDemoEnv")) - .append(message).append(Inter.getLocText("FR-Designer_Utils-switch")).toString(); + text = Inter.getLocText("FR-Designer_Open") + + ProductConstants.APP_NAME + + Inter.getLocText("FR-Designer_Utils-OpenDemoEnv") + + message + Inter.getLocText("FR-Designer_Utils-switch"); } else { - text = new StringBuffer(Inter.getLocText("FR-Designer_Open")) - .append(ProductConstants.APP_NAME) - .append(Inter.getLocText("FR-Designer_Utils-NewDemoEnv")) - .append(message).append(Inter.getLocText("FR-Designer_Utils-switch")).toString(); + text = Inter.getLocText("FR-Designer_Open") + + ProductConstants.APP_NAME + + Inter.getLocText("FR-Designer_Utils-NewDemoEnv") + + message + Inter.getLocText("FR-Designer_Utils-switch"); } UITextArea a = new UITextArea(text); a.setFont(new Font("Dialog", Font.PLAIN, 12)); @@ -224,12 +165,13 @@ public class StartServer { a.setLineWrap(true); this.add(a); } - + @Override protected String title4PopupWindow() { + return Inter.getLocText("FR-Designer_Tooltips"); } - + } - + } \ No newline at end of file diff --git a/designer-base/src/com/fr/start/TomcatFRHost.java b/designer-base/src/com/fr/start/TomcatFRHost.java deleted file mode 100644 index 585564b90..000000000 --- a/designer-base/src/com/fr/start/TomcatFRHost.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.fr.start; - -import java.io.File; -import javax.servlet.ServletException; -import org.apache.catalina.Context; -import org.apache.catalina.LifecycleException; -import org.apache.catalina.core.AprLifecycleListener; -import org.apache.catalina.core.StandardServer; -import org.apache.catalina.startup.Tomcat; - -public class TomcatFRHost { - private static Tomcat tomcat; - - public static Tomcat getTomcat() { - return tomcat; - } - - private static StandardServer server; - - private static AprLifecycleListener listener; - - public static void main(String[] args) throws Exception { - tomcat = new Tomcat(); - // 主机名,或ip -// tomcat.setHostname("localhost"); - // 设置端口,80为默认端口 - tomcat.setPort(8071); - // tomcat用于存储自身的信息,可以随意指定,最好包含在项目目录下 - tomcat.setBaseDir("."); - // 建立server参照tomcat文件结构 - server = (StandardServer) tomcat.getServer(); - listener = new AprLifecycleListener(); - server.addLifecycleListener(listener); - // 将appBase设为本项目所在目录 - //tomcat.getHost().setAppBase("."); - tomcat.getHost().setAppBase( - System.getProperty("user.dir") + File.separator + "."); - - // 第二个参数对应docBase为web应用路径,目录下应有WEB-INF,WEB-INF下要有web.xml - // 启动tomcat - try { - tomcat.start(); - Context ct1 = tomcat.addWebapp("/WebReport", "/Users/momeak/Documents/Working/develop/others/tomcatsrc/WebReport"); - } catch (LifecycleException e) { - e.printStackTrace(); - } catch (ServletException e) { - e.printStackTrace(); - } -// Context ct1 = tomcat.addWebapp("/examples", "/Users/momeak/Documents/Working/develop/others/tomcatsrc/examples"); - -// Context ct = tomcat.addWebapp("", "/Users/momeak/Documents/Working/develop/others/tomcatsrc/webapps/ROOT"); - -// tomcat.getServer().await(); - System.out.println("启动成功"); - } -} diff --git a/designer-base/src/com/fr/start/server/EmbedServerEvent.java b/designer-base/src/com/fr/start/server/EmbedServerEvent.java new file mode 100644 index 000000000..ced743217 --- /dev/null +++ b/designer-base/src/com/fr/start/server/EmbedServerEvent.java @@ -0,0 +1,15 @@ +package com.fr.start.server; + +import com.fr.event.Event; +import com.fr.event.Null; + +/** + * Created by juhaoyu on 2018/6/5. + * 内置服务器事件 + */ +public enum EmbedServerEvent implements Event { + BeforeStart, + AfterStart, + BeforeStop, + AfterStop +} diff --git a/designer-base/src/com/fr/start/server/FRTomcat.java b/designer-base/src/com/fr/start/server/FRTomcat.java deleted file mode 100644 index 46c529697..000000000 --- a/designer-base/src/com/fr/start/server/FRTomcat.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.fr.start.server; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.servlet.ServletException; -import org.apache.catalina.Context; -import org.apache.catalina.Host; -import org.apache.catalina.core.ContainerBase; -import org.apache.catalina.core.StandardContext; -import org.apache.catalina.core.StandardHost; -import org.apache.catalina.startup.ContextConfig; -import org.apache.catalina.startup.Tomcat; - -public class FRTomcat extends Tomcat{ - - private final Map frpinnedLoggers = new HashMap(); - private boolean frsilent = false; - - - public Context addWebapp(String contextPath, String docBase) throws ServletException { - silence(host, contextPath); - - Context ctx = createContext(host, contextPath); - if (ctx instanceof StandardContext) { - ((StandardContext)ctx).setDelegate(true); - } - ctx.setPath(contextPath); - ctx.setDocBase(docBase); - - ctx.addLifecycleListener(new DefaultWebXmlListener()); - ctx.setConfigFile(getWebappConfigFile(docBase, contextPath)); - - ContextConfig ctxCfg = new ContextConfig(); - ctx.addLifecycleListener(ctxCfg); - - ctxCfg.setDefaultWebXml(noDefaultWebXmlPath()); - - if (host == null) { - getHost().addChild(ctx); - } else { - host.addChild(ctx); - } - - return ctx; - } - - private void silence(Host host, String contextPath) { - String loggerName = getLoggerName(host, contextPath); - Logger logger = Logger.getLogger(loggerName); - frpinnedLoggers.put(loggerName, logger); - if (frsilent) { - logger.setLevel(Level.WARNING); - } else { - logger.setLevel(Level.INFO); - } - } - - private String getLoggerName(Host host, String contextName) { - if (host == null) { - host = getHost(); - } - StringBuilder loggerName = new StringBuilder(); - loggerName.append(ContainerBase.class.getName()); - loggerName.append(".["); - // Engine name - loggerName.append(host.getParent().getName()); - loggerName.append("].["); - // Host name - loggerName.append(host.getName()); - loggerName.append("].["); - // Context name - if (contextName == null || contextName.equals("")) { - loggerName.append("/"); - } else if (contextName.startsWith("##")) { - loggerName.append("/"); - loggerName.append(contextName); - } - loggerName.append(']'); - - return loggerName.toString(); - } - - private Context createContext(Host host, String url) { - String contextClass = StandardContext.class.getName(); - if (host == null) { - host = this.getHost(); - } - if (host instanceof StandardHost) { - contextClass = ((StandardHost) host).getContextClass(); - } - try { - return (Context) Class.forName(contextClass).getConstructor() - .newInstance(); - } catch (InstantiationException e) { - throw new IllegalArgumentException( - "Can't instantiate context-class " + contextClass - + " for host " + host + " and url " - + url, e); - } catch (IllegalAccessException e) { - throw new IllegalArgumentException( - "Can't instantiate context-class " + contextClass - + " for host " + host + " and url " - + url, e); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException( - "Can't instantiate context-class " + contextClass - + " for host " + host + " and url " - + url, e); - } catch (InvocationTargetException e) { - throw new IllegalArgumentException( - "Can't instantiate context-class " + contextClass - + " for host " + host + " and url " - + url, e); - } catch (NoSuchMethodException e) { - throw new IllegalArgumentException( - "Can't instantiate context-class " + contextClass - + " for host " + host + " and url " - + url, e); - } catch (SecurityException e) { - throw new IllegalArgumentException( - "Can't instantiate context-class " + contextClass - + " for host " + host + " and url " - + url, e); - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException( - "Can't instantiate context-class " + contextClass - + " for host " + host + " and url " - + url, e); - } - } -} diff --git a/designer-base/src/com/fr/start/server/FineEmbedServer.java b/designer-base/src/com/fr/start/server/FineEmbedServer.java new file mode 100644 index 000000000..81ca3793f --- /dev/null +++ b/designer-base/src/com/fr/start/server/FineEmbedServer.java @@ -0,0 +1,119 @@ +package com.fr.start.server; + +import com.fr.base.FRContext; +import com.fr.design.DesignerEnvManager; +import com.fr.event.EventDispatcher; +import com.fr.log.FineLoggerFactory; +import com.fr.module.ModuleRole; +import com.fr.stable.lifecycle.AbstractLifecycle; +import com.fr.startup.FineWebApplicationInitializer; +import com.fr.third.springframework.web.SpringServletContainerInitializer; +import com.fr.third.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.apache.catalina.Context; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.loader.VirtualWebappLoader; +import org.apache.catalina.startup.Tomcat; + +import java.io.File; +import java.util.HashSet; +import java.util.Set; + +/** + * Created by juhaoyu on 2018/6/5. + */ +public class FineEmbedServer extends AbstractLifecycle { + + private static final FineEmbedServer INSTANCE = new FineEmbedServer(); + + private Tomcat tomcat; + + public static FineEmbedServer getInstance() { + + return INSTANCE; + } + + private FineEmbedServer() {} + + @Override + protected synchronized void executeStart() { + + EventDispatcher.fire(EmbedServerEvent.BeforeStart); + try { + //初始化tomcat + initTomcat(); + tomcat.start(); + } catch (LifecycleException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + EventDispatcher.fire(EmbedServerEvent.AfterStart); + } + + private void initTomcat() { + + tomcat = new Tomcat(); + + //覆盖tomcat的WebAppClassLoader + tomcat.setPort(DesignerEnvManager.getEnvManager().getInnerServerPort()); + String docBase = new File(FRContext.getCurrentEnv().getPath()).getParent(); + String appName = "/" + FRContext.getCurrentEnv().getAppName(); + Context context = tomcat.addContext(appName, docBase); + tomcat.addServlet(appName, "default", "org.apache.catalina.servlets.DefaultServlet"); + context.setLoader(new FRTomcatLoader()); + + //直接指定initializer,tomcat就不用再扫描一遍了 + SpringServletContainerInitializer initializer = new SpringServletContainerInitializer(); + Set> classes = new HashSet>(); + classes.add(FineWebApplicationInitializer.class); + context.addServletContainerInitializer(initializer, classes); + } + + @Override + protected synchronized void executeStop() { + + EventDispatcher.fire(EmbedServerEvent.BeforeStop); + try { + stopSpring(); + stopServerActivator(); + stopTomcat(); + } catch (LifecycleException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + EventDispatcher.fire(EmbedServerEvent.AfterStop); + } + + private void stopServerActivator() { + + ModuleRole.ServerRoot.stop(); + } + + private void stopSpring() { + + AnnotationConfigWebApplicationContext context = ModuleRole.ServerRoot.getSingleton(AnnotationConfigWebApplicationContext.class); + if (context != null) { + context.stop(); + context.destroy(); + } + } + + private void stopTomcat() throws LifecycleException { + + tomcat.stop(); + tomcat.destroy(); + } + + + /** + * Created by juhaoyu on 2018/6/5. + * 自定义的tomcat loader,主要用于防止内置服务器再加载一遍class + */ + private static class FRTomcatLoader extends VirtualWebappLoader { + + @Override + public ClassLoader getClassLoader() { + + return this.getClass().getClassLoader(); + } + + } + +} diff --git a/designer-base/src/com/fr/start/server/MultiOutputStream.java b/designer-base/src/com/fr/start/server/MultiOutputStream.java deleted file mode 100644 index 08580f2ef..000000000 --- a/designer-base/src/com/fr/start/server/MultiOutputStream.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.fr.start.server; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; - -/** - * p: 这是为了将一个OutputStream输出多个OutputStream - */ -public class MultiOutputStream extends OutputStream { - private List outList = new ArrayList(); - - public MultiOutputStream() { - } - - public void addOutputStream(OutputStream output) { - this.outList.add(output); - } - - public void removeOutputStream(OutputStream output) { - this.outList.remove(output); - } - - public int getOutputStreamCount() { - return this.outList.size(); - } - - public OutputStream getOutputStream(int index) { - return (OutputStream) this.outList.get(index); - } - - public void write(int b) throws IOException { - for(int i = 0; i < outList.size(); i++) { - ((OutputStream)outList.get(i)).write(b); - } - } - - public void write(byte buff[]) throws IOException { - for(int i = 0; i < outList.size(); i++) { - ((OutputStream)outList.get(i)).write(buff); - } - } - - public void write(byte buff[], int off, int len) throws IOException { - for(int i = 0; i < outList.size(); i++) { - ((OutputStream)outList.get(i)).write(buff, off, len); - } - } - - public void flush() throws IOException { - for(int i = 0; i < outList.size(); i++) { - ((OutputStream)outList.get(i)).flush(); - } - } - - public void close() throws IOException { - for(int i = 0; i < outList.size(); i++) { - ((OutputStream)outList.get(i)).close(); - } - } -} \ No newline at end of file diff --git a/designer-base/src/com/fr/start/server/ServerManageFrame.java b/designer-base/src/com/fr/start/server/ServerManageFrame.java index 02d60b5f4..4f05cdeaf 100644 --- a/designer-base/src/com/fr/start/server/ServerManageFrame.java +++ b/designer-base/src/com/fr/start/server/ServerManageFrame.java @@ -1,27 +1,20 @@ package com.fr.start.server; -import java.awt.BorderLayout; -import java.awt.Desktop; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.BorderFactory; -import javax.swing.JFrame; - -import com.fr.base.FRContext; -import com.fr.design.gui.ilable.UILabel; -import javax.swing.JPanel; -import javax.swing.SwingConstants; - import com.fr.base.BaseUtils; +import com.fr.base.FRContext; import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.general.Inter; -import com.fr.start.StartServer; import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.Inter; +import com.fr.start.ServerStarter; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; /** * 内置Tomcat服务器管理界面 @@ -29,11 +22,11 @@ import com.fr.design.utils.gui.GUICoreUtils; public class ServerManageFrame extends JFrame { // 由于实际情况,只需要一个当前对象的Instance. private static ServerManageFrame serverManageFrame = null; - private TomcatHost hostTomcatServer; - public static ServerManageFrame getServerManageFrame(TomcatHost hostTomcatServer) { - if(serverManageFrame == null) { - serverManageFrame = new ServerManageFrame(hostTomcatServer); + static ServerManageFrame getServerManageFrame() { + + if (serverManageFrame == null) { + serverManageFrame = new ServerManageFrame(); } //p:每次启动之前都需要检查按钮的Enabled属性. @@ -49,8 +42,7 @@ public class ServerManageFrame extends JFrame { private JPanel startPane; private JPanel stopPane; - private ServerManageFrame(TomcatHost hostTomcatServer) { - this.hostTomcatServer = hostTomcatServer; + private ServerManageFrame() { DesignUtils.initLookAndFeel(); this.setIconImage(BaseUtils.readImage("/com/fr/base/images/oem/trayStarted.png")); @@ -82,12 +74,8 @@ public class ServerManageFrame extends JFrame { startPane.add(new UILabel(Inter.getLocText("Server-Start"))); startButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - TomcatHost tomcatServer = StartServer.getInstance(); try { - if(!tomcatServer.isStarted()) { - tomcatServer.start(); - tomcatServer.addAndStartLocalEnvHomeWebApp(); - } + FineEmbedServer.getInstance().start(); checkButtonEnabled(); } catch(Exception exp) { FRContext.getLogger().error(exp.getMessage()); @@ -103,11 +91,8 @@ public class ServerManageFrame extends JFrame { stopPane.add(new UILabel(Inter.getLocText("Server-Stop"))); stopButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - TomcatHost tomcatServer = StartServer.getInstance(); try { - if(tomcatServer.isStarted()) { - tomcatServer.stop(); - } + FineEmbedServer.getInstance().stop(); checkButtonEnabled(); } catch(Exception exp) { FRContext.getLogger().error(exp.getMessage()); @@ -125,24 +110,21 @@ public class ServerManageFrame extends JFrame { infoPane.add(logPathTextField, BorderLayout.CENTER); logPathTextField.setEditable(false); - // logfile - logPathTextField.setText(hostTomcatServer.getOutLogFile().getPath()); - UIButton openButton = new UIButton(); infoPane.add(openButton, BorderLayout.EAST); openButton.setIcon(BaseUtils.readIcon("/com/fr/design/images/server/view.png")); openButton.setToolTipText(Inter.getLocText("Open")); - openButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent evt) { - - Desktop desktop = Desktop.getDesktop(); - try { - desktop.open(ServerManageFrame.this.hostTomcatServer.getOutLogFile()); - } catch(Exception exp) { - FRContext.getLogger().error(exp.getMessage()); - } - } - }); +// openButton.addActionListener(new ActionListener() { +// public void actionPerformed(ActionEvent evt) { +// +// Desktop desktop = Desktop.getDesktop(); +// try { +// desktop.open(); +// } catch(Exception exp) { +// FRContext.getLogger().error(exp.getMessage()); +// } +// } +// }); this.setSize(420, 160); this.setTitle(Inter.getLocText("Server-Embedded_Server")); @@ -154,8 +136,8 @@ public class ServerManageFrame extends JFrame { * @throws Exception 异常 */ public void checkButtonEnabled() throws Exception { - TomcatHost tomcatServer = StartServer.getInstance(); - if(tomcatServer.isStarted()) { + + if (ServerStarter.isStarted()) { GUICoreUtils.setEnabled(startPane, false); GUICoreUtils.setEnabled(stopPane, true); } else { diff --git a/designer-base/src/com/fr/start/server/ServerTray.java b/designer-base/src/com/fr/start/server/ServerTray.java index c1f4bb5ae..05e35a40f 100644 --- a/designer-base/src/com/fr/start/server/ServerTray.java +++ b/designer-base/src/com/fr/start/server/ServerTray.java @@ -1,82 +1,72 @@ package com.fr.start.server; -import java.awt.AWTException; -import java.awt.Image; -import java.awt.MenuItem; -import java.awt.PopupMenu; -import java.awt.SystemTray; -import java.awt.TrayIcon; +import com.fr.base.BaseUtils; +import com.fr.base.FRContext; +import com.fr.general.Inter; + +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import com.fr.base.BaseUtils; -import com.fr.base.FRContext; -import com.fr.general.Inter; -import com.fr.start.StartServer; - /** * Create server tray. */ public class ServerTray { - public static boolean JVM_EXIT_ON_TRAY_EXIT = false; - - private MenuItem manangeMenu, startMenu, stopMenu, exitMenu; - private Image trayStartedImage = BaseUtils.readImage( - "/com/fr/base/images/oem/trayStarted.png"); - private Image trayStoppedImage = BaseUtils.readImage( - "/com/fr/base/images/oem/trayStopped.png"); + + private static ServerTray INSTANCE; + + private MenuItem startMenu; + + private MenuItem stopMenu; + + private Image trayStartedImage = BaseUtils.readImage("/com/fr/base/images/oem/trayStarted.png"); + + private Image trayStoppedImage = BaseUtils.readImage("/com/fr/base/images/oem/trayStopped.png"); private ServerManageFrame serverManageFrame; private TrayIcon trayIcon; - - private TomcatHost hostTomcatServer; - - - public ServerTray(TomcatHost hostTomcatServer) { - - this.hostTomcatServer = hostTomcatServer; - + + + public ServerTray() { + //p:首先构建右键菜单 PopupMenu popup = new PopupMenu(); - manangeMenu = new MenuItem(Inter.getLocText("Server-Open_Service_Manager")); + MenuItem manangeMenu = new MenuItem(Inter.getLocText("Server-Open_Service_Manager")); manangeMenu.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { - serverManageFrame = ServerManageFrame.getServerManageFrame(ServerTray.this.hostTomcatServer); - if(!serverManageFrame.isVisible()) { - serverManageFrame.setVisible(true); - } - serverManageFrame.toFront();//p:到第一个. + + serverManageFrame = ServerManageFrame.getServerManageFrame(); + if (!serverManageFrame.isVisible()) { + serverManageFrame.setVisible(true); + } + serverManageFrame.toFront();//p:到第一个. } }); startMenu = new MenuItem(Inter.getLocText("FR-Server_Embedded_Server_Start")); stopMenu = new MenuItem(Inter.getLocText("FR-Server_Embedded_Server_Stop")); - exitMenu = new MenuItem(Inter.getLocText("Exit")); + MenuItem exitMenu = new MenuItem(Inter.getLocText("Exit")); //创建打开监听器 ActionListener startListener = new ActionListener() { + public void actionPerformed(ActionEvent e) { - TomcatHost tomcatServer = StartServer.getInstance(); + try { - if(!tomcatServer.isStarted()) { - tomcatServer.start(); - tomcatServer.addAndStartLocalEnvHomeWebApp();//暂停后再打开Tomcat,需要addApp - } - } catch(Exception exp) { - FRContext.getLogger().error(exp.getMessage(), exp); + FineEmbedServer.getInstance().start(); + } catch (Exception exp) { + FRContext.getLogger().error(exp.getMessage(), exp); } } }; ActionListener stopListener = new ActionListener() { public void actionPerformed(ActionEvent e) { - TomcatHost tomcatServer = StartServer.getInstance(); try { - if(tomcatServer.isStarted()) { - tomcatServer.stop(); - } - } catch(Exception exp) { - FRContext.getLogger().error(exp.getMessage(), exp); + FineEmbedServer.getInstance().stop(); + } catch (Throwable exp) { + FRContext.getLogger().error(exp.getMessage(), exp); } } }; @@ -105,18 +95,18 @@ public class ServerTray { if(e.getClickCount() < 2) { return; } - - ServerManageFrame serverManageFrame = ServerManageFrame.getServerManageFrame(ServerTray.this.hostTomcatServer); - if(!serverManageFrame.isVisible()) { - serverManageFrame.setVisible(true); - } - serverManageFrame.toFront();//p:到第一个. - } + + ServerManageFrame serverManageFrame = ServerManageFrame.getServerManageFrame(); + if (!serverManageFrame.isVisible()) { + serverManageFrame.setVisible(true); + } + serverManageFrame.toFront();//p:到第一个. + } }); - - TrayIcon[] ti = SystemTray.getSystemTray().getTrayIcons(); - for(int i = 0;i webAppsMap = new HashMap(); - private List listenerList = new ArrayList(); - private boolean isDemoAppLoaded = false; - - public TomcatHost(int port) { - this.currentPort = port; - initServer(); - - initLogFileAndOutputStream(); - - // TODO: 将HostTomcatServer放到ServerTray中去 - tryStartServerTray(); - } - - public static FRTomcat getTomcat() { - return tomcat; - } - - private void initServer() { - try { - //直接用自定义的,不用server.xml - this.tomcat = new FRTomcat(); - this.tomcat.setPort(this.currentPort); - this.tomcat.setBaseDir(StableUtils.getInstallHome()); - this.server = (StandardServer) tomcat.getServer(); - this.listener = new AprLifecycleListener(); - this.server.addLifecycleListener(listener); - this.tomcat.getHost().setAppBase(StableUtils.getInstallHome() + File.separator + "."); - this.tomcat.getConnector().setURIEncoding("UTF-8"); - } catch (Exception e) { - //todo 最好加一个用server.xml - FRContext.getLogger().error(e.getMessage(), e); - } - } - - private void initLogFileAndOutputStream() { - // log文件放置的位置 - File logDir = null; - String installHome = StableUtils.getInstallHome(); - if (installHome == null) {// 没有installHome的时候,就放到user.home下面喽 - logDir = new File(ProductConstants.getEnvHome() + File.separator + ProjectConstants.LOGS_NAME); - } else { - // james:logs放在安装目录下面 - logDir = new File(installHome + File.separator + ProjectConstants.LOGS_NAME + File.separator + "tomcat"); - } - StableUtils.mkdirs(logDir); - DateFormat fateFormat = new SimpleDateFormat("yyyy-MM-dd"); - Calendar curCalendar = Calendar.getInstance(); - outLogFile = new File(logDir, "tomcat_" + fateFormat.format(curCalendar.getTime()) + ".log"); - - try { - multiOutputStream = new MultiOutputStream(); - multiOutputStream.addOutputStream(new FileOutputStream(outLogFile, true)); - multiOutputStream.addOutputStream(System.out); - System.setErr(new PrintStream(multiOutputStream)); - System.setOut(new PrintStream(multiOutputStream)); - } catch (IOException ioe) { - FRContext.getLogger().error(ioe.getMessage(), ioe); - } - } - - private synchronized void addWebApplication(String context, String webappsPath) { - FRContext.getLogger().info("The new Application Path is: \n" + webappsPath + ", it will be added."); - if (webAppsMap.get(context) != null) { - Context webapp = webAppsMap.remove(context); - } - try { - if (!isStarted()) { - start(); - } - Context webapp = tomcat.addWebapp(context, webappsPath); - webAppsMap.put(context, webapp); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - } - } - - private void addAndStartWebApplication(String context, String webAppPath) { - addWebApplication(context, webAppPath); - } - - /** - * Get MultiOutputStream. - */ - public MultiOutputStream getMultiOutputStream() { - return this.multiOutputStream; - } - - /** - * Get out log file - */ - public File getOutLogFile() { - return this.outLogFile; - } - - private Server getServer() { - if (server == null) { - initServer(); - } - - return server; - } - - /** - * Start - * - * @throws Exception - */ - public void start() throws Exception { - tomcat.start(); - for (int i = 0; i < listenerList.size(); i++) { - TomcatServerListener listener = TomcatHost.this.getLinstener(i); - listener.started(this); - } - } - - /** - * Stop - * - * @throws Exception - */ - public void stop() throws Exception { - - tomcat.stop(); - - for (int i = 0; i < listenerList.size(); i++) { - TomcatServerListener listener = this.getLinstener(i); - listener.stopped(this); - } - - StartServer.currentEnvChanged(); - server = null;//重置server - } - - /** - * Is started - * - * @throws Exception - */ - public boolean isStarted() throws Exception { - return getServer().getState().isAvailable(); - } - - public void addListener(TomcatServerListener listener) { - this.listenerList.add(listener); - } - - public int getLinstenerCount() { - return this.listenerList.size(); - } - - public TomcatServerListener getLinstener(int index) { - if (index < 0 || index >= this.getLinstenerCount()) { - return null; - } - - return this.listenerList.get(index); - } - - public void clearLinsteners() { - this.listenerList.clear(); - } - - /** - * 尝试启动系统托盘 - */ - private void tryStartServerTray() { - if (SystemTray.isSupported()) { - new ServerTray(this); - } else { - FRContext.getLogger().error("Do not support the SystemTray!"); - } - } - - public void exit() { - try { - getServer().stop(); - } catch (LifecycleException e) { - FRContext.getLogger().error(e.getMessage(), e); - } - - for (int i = 0; i < listenerList.size(); i++) { - TomcatServerListener listener = this.getLinstener(i); - listener.exited(this); - } - - try { - getServer().destroy(); - } catch (LifecycleException e) { - FRContext.getLogger().error(e.getMessage(), e); - } - StartServer.currentEnvChanged(); - - } - - public int getCurrentPort() { - return currentPort; - } - - /** - * 安装目录下的默认的WebReport,这个只执行一次,除了预览demo,其他的不要调用这个方法 - */ - public void addAndStartInstallHomeWebApp() { - if (!isDemoAppLoaded) { - String installHome = StableUtils.getInstallHome(); - String webApplication = StableUtils.pathJoin(new String[]{installHome, ProjectConstants.WEBAPP_NAME}); - - if (new File(webApplication).isDirectory()) { - addAndStartWebApplication("/" + ProjectConstants.WEBAPP_NAME, webApplication); - } - } - isDemoAppLoaded = true; - } - - /** - * 加载Env下的报表运行环境 - */ - public void addAndStartLocalEnvHomeWebApp() { - String name = DesignerEnvManager.getEnvManager().getCurEnvName(); - if (name.equals(Inter.getLocText("Default"))) { - isDemoAppLoaded = true; - } - Env env = FRContext.getCurrentEnv(); - if (env instanceof LocalEnv) { - String webApplication = new File(env.getPath()).getParent(); - FRContext.getLogger().info(Inter.getLocText("INFO-Reset_Webapp") + ":" + webApplication); - addAndStartWebApplication("/" + GeneralContext.getCurrentAppNameOfEnv(), webApplication); - } - } - - public boolean isDemoAppLoaded() { - return isDemoAppLoaded; - } - -} \ No newline at end of file diff --git a/designer-base/src/com/fr/start/server/TomcatServerListener.java b/designer-base/src/com/fr/start/server/TomcatServerListener.java deleted file mode 100644 index 30702d340..000000000 --- a/designer-base/src/com/fr/start/server/TomcatServerListener.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.fr.start.server; - -public interface TomcatServerListener { - /** - * Started - */ - public void started(TomcatHost tomcatServer); - - /** - * Stopped - */ - public void stopped(TomcatHost tomcatServer); - /** - * Exited - */ - public void exited(TomcatHost tomcatServer); - -} \ No newline at end of file diff --git a/designer-chart/src/com/fr/van/chart/map/server/ChartMapEditorAction.java b/designer-chart/src/com/fr/van/chart/map/server/ChartMapEditorAction.java index 9c8096cde..560bfafca 100644 --- a/designer-chart/src/com/fr/van/chart/map/server/ChartMapEditorAction.java +++ b/designer-chart/src/com/fr/van/chart/map/server/ChartMapEditorAction.java @@ -8,7 +8,7 @@ import com.fr.design.actions.UpdateAction; import com.fr.general.GeneralContext; import com.fr.general.IOUtils; import com.fr.general.Inter; -import com.fr.start.StartServer; +import com.fr.start.ServerStarter; import java.awt.event.ActionEvent; @@ -23,11 +23,11 @@ public class ChartMapEditorAction extends UpdateAction { } public void actionPerformed(ActionEvent evt) { - int port = DesignerEnvManager.getEnvManager().getJettyServerPort(); + int port = DesignerEnvManager.getEnvManager().getInnerServerPort(); String web = GeneralContext.getCurrentAppNameOfEnv(); String serverlet = ServerConfig.getInstance().getReportServletName(); Env env = FRContext.getCurrentEnv(); - StartServer.browserURLWithLocalEnv(env.isLocalEnv() ? String.format("http://localhost:%d/%s/%s?op=map", port, web, serverlet) : env.getPath() + "?op=map"); + ServerStarter.browserURLWithLocalEnv(env.isLocalEnv() ? String.format("http://localhost:%d/%s/%s?op=map", port, web, serverlet) : env.getPath() + "?op=map"); } } diff --git a/designer-realize/src/com/fr/start/Designer.java b/designer-realize/src/com/fr/start/Designer.java index ae382d2fa..3a93387eb 100644 --- a/designer-realize/src/com/fr/start/Designer.java +++ b/designer-realize/src/com/fr/start/Designer.java @@ -48,6 +48,8 @@ import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.stable.xml.XMLTools; import com.fr.start.module.StartupArgs; +import com.fr.start.server.ServerTray; +import com.fr.start.server.FineEmbedServer; import javax.swing.JComponent; import javax.swing.JPanel; @@ -92,7 +94,8 @@ public class Designer extends BaseDesigner { designerRoot.start(); if (FRContext.getCurrentEnv() instanceof LocalEnv) { // 预启动一下 - StartServer.start(); + FineEmbedServer.getInstance().start(); + ServerTray.init(); } } diff --git a/designer-realize/src/com/fr/start/module/DesignerEnvProvider.java b/designer-realize/src/com/fr/start/module/DesignerEnvProvider.java index 68e7a4c9a..d7b3c975c 100644 --- a/designer-realize/src/com/fr/start/module/DesignerEnvProvider.java +++ b/designer-realize/src/com/fr/start/module/DesignerEnvProvider.java @@ -19,7 +19,7 @@ import com.fr.file.filetree.FileNode; import com.fr.general.ComparatorUtils; import com.fr.module.Activator; import com.fr.start.EnvSwitcher; -import com.fr.start.StartServer; +import com.fr.start.ServerStarter; import java.io.InputStream; import java.io.OutputStream; @@ -38,7 +38,7 @@ public class DesignerEnvProvider extends Activator { for (String arg : args) { if (ComparatorUtils.equals(arg, "demo")) { DesignerEnvManager.getEnvManager().setCurrentEnv2Default(); - StartServer.browserDemoURL(); + ServerStarter.browserDemoURL(); break; } }