Through repeated follow-up, gwt-dev-windows used in the service container embedded version of Tomcat, as to how to run a lot of embedded Tomcat web here to say the least, this is only guide text, and guide how foreigners look the code is how to written so well.



First, from the js compiler GWTShellServlet Ways genSelectionScript And this method to create a StandardLinkerContext object, constructed at a time when this object to check whether the module output path is empty, and the module's property into the object map, and then return to the Ways genSelectionScript Next, create a StandardLinker object, this object on the js from the template file replacement (replace) a just StandardLinkerContext, property, and then complete this js method. Js at the template was after replacement, under the hair to the browser, the browser on the js analytic, we will trigger the request hosted.html server.



As for the entire servlet call flow, you can refer to the following URL:



GWT's gwt-dev-windows.jar the GWTShellServlet call flow

http://samwong.javaeye.com/admin/blogs/342005







  /**
   * Generates a module.js file on the fly. Note that the nocache file that is
   * generated that can only be used for hosted mode. It cannot produce a web
   * mode version, since this servlet doesn't know strong names, since by
   * definition of "hosted mode" JavaScript hasn't been compiled at this point.
   */
  private String genSelectionScript(TreeLogger logger, String moduleName)
      throws UnableToCompleteException {
	  System.out.println("=== genSelectionScript ===");
    logger.log(TreeLogger.TRACE,
        "Generating a script selection script for module " + moduleName);

    StandardLinkerContext context = new StandardLinkerContext(logger,
        getModuleDef(logger, moduleName), null, null, new JJSOptions());
    HostedModeLinker linker = new HostedModeLinker();
    return linker.generateSelectionScript(logger, context,
        context.getArtifacts());
  }











 public StandardLinkerContext(TreeLogger logger, ModuleDef module,
      File moduleOutDir, File generatorDir, JJSOptions jjsOptions) {
    logger = logger.branch(TreeLogger.DEBUG,
        "Constructing StandardLinkerContext", null);

    this.jjsOptions = jjsOptions;
    this.moduleFunctionName = module.getFunctionName();
    this.moduleName = module.getName();
    this.moduleOutDir = moduleOutDir;
    this.linkerClasses = new ArrayList<Class<? extends Linker>>(
        module.getActiveLinkers());
    linkerClasses.add(module.getActivePrimaryLinker());
    System.out.println("模块路径:[" +  moduleOutDir + "]");
    if (moduleOutDir != null) {
      compilationsDir = new File(moduleOutDir.getParentFile(),
          GWTCompiler.GWT_COMPILER_DIR + File.separator + moduleName
              + File.separator + "compilations");
      System.out.println("编译输出路径:[" + compilationsDir.getPath() + "]");
      Util.recursiveDelete(compilationsDir, true);
      compilationsDir.mkdirs();
      logger.log(TreeLogger.SPAM, "compilationsDir: "
          + compilationsDir.getPath(), null);

      this.moduleAuxDir = new File(moduleOutDir.getParentFile(), moduleName
          + "-aux");
      if (moduleAuxDir.exists()) {
        Util.recursiveDelete(moduleAuxDir, false);
      }
      logger.log(TreeLogger.SPAM, "mouduleAuxDir: " + moduleAuxDir.getPath(),
          null);
    } else {
      compilationsDir = null;
      moduleAuxDir = null;
    }

    for (Map.Entry<String, Class<? extends Linker>> entry : module.getLinkers().entrySet()) {
      linkerShortNames.put(entry.getValue(), entry.getKey());
    }

    /*
     * This will make all private PublicResources and GeneratedResources appear
     * in the root of the module auxiliary directory.
     */
    linkerShortNames.put(this.getClass(), "");

    // Always return the properties in the same order as a convenience
    SortedSet<SelectionProperty> mutableProperties = new TreeSet<SelectionProperty>(
        SELECTION_PROPERTY_COMPARATOR);
    for (Property p : module.getProperties()) {
      // Create a new view
      StandardSelectionProperty newProp = new StandardSelectionProperty(p);
      mutableProperties.add(newProp);
      propertiesByName.put(newProp.getName(), newProp);
      logger.log(TreeLogger.SPAM, "Added property " + newProp, null);
    }
    properties = Collections.unmodifiableSortedSet(mutableProperties);

    {
      int index = 0;
      for (Script script : module.getScripts()) {
        artifacts.add(new StandardScriptReference(script.getSrc(), index++));
        logger.log(TreeLogger.SPAM, "Added script " + script.getSrc(), null);
      }
    }

    {
      int index = 0;
      for (String style : module.getStyles()) {
        artifacts.add(new StandardStylesheetReference(style, index++));
        logger.log(TreeLogger.SPAM, "Added style " + style, null);
      }
    }

    // Generated files should be passed in via addArtifacts()

    for (String path : module.getAllPublicFiles()) {
      String partialPath = path.replace(File.separatorChar, '/');
      PublicResource resource = new StandardPublicResource(partialPath,
          module.findPublicFile(path));
      artifacts.add(resource);
      logger.log(TreeLogger.SPAM, "Added public resource " + resource, null);
    }
  }