code: public static void installResourceExtension(DatabaseClient client)
      throws IOException
    {
      // create a manager for resource extensions
      ResourceExtensionsManager resourceMgr = client.newServerConfigManager().newResourceExtensionsManager();
  
      // specify metadata about the resource extension
      ExtensionMetadata metadata = new ExtensionMetadata();
      metadata.setTitle("Search Collector Resource Services");
      metadata.setDescription("This plugin collects documents qualified by search");
      metadata.setProvider("MarkLogic");
      metadata.setVersion("0.1");
  
      // acquire the resource extension source code
      try ( InputStream sourceStream = Util.openStream("scripts"+File.separator+SearchCollector.NAME+".xqy") ) {
        if (sourceStream == null) throw new RuntimeException("Could not read example resource extension");
  
        // create a handle on the extension source code
        InputStreamHandle handle = new InputStreamHandle(sourceStream);
        handle.set(sourceStream);
  
        MethodParameters getParams = new MethodParameters(MethodType.GET);
        getParams.add("format",     "xs:string");
        getParams.add("options",    "xs:string");
        getParams.add("pageLength", "xs:string");
        getParams.add("start",      "xs:string");
        getParams.add("view",       "xs:string");
  
        getParams.add("q",          "xs:string");
  
        MethodParameters postParams = new MethodParameters(MethodType.POST);
        postParams.add("format",     "xs:string");
        postParams.add("options",    "xs:string");
        postParams.add("pageLength", "xs:string");
        postParams.add("start",      "xs:string");
        postParams.add("view",       "xs:string");
  
        // write the resource extension to the database
        resourceMgr.writeServices(SearchCollector.NAME, handle, metadata, getParams, postParams);
      }
  
      System.out.println("Installed the resource extension on the server");
    }
docs: install the resource extension on the server