Ce contenu n'est pas disponible dans la langue sélectionnée.

6.3. Creating a New Module Source Type


JBoss ON can load a CommonJS script module from different locations, including both local directories and remote repositories.
It is possible to create support for loading modules from a different source, such as a URL. Creating a new module source location requires three things:
  • Creating a new ScriptSourceProvider interface.
  • Adding the Java service entry in the META-INF/services directory of a JAR for the class.
  • Putting the new JAR into the lib/ directory of the CLI installation directory to be available to clients and in serverRoot/jon-server-3.3/modules/org/rhq/server-startup/main/deployments/rhq.ear/lib on the JBoss ON server so that it is available to server-side scripts (alert scripts).

Example 6.1. HTTP Module Source Location

This script source provider downloads a script module from a given URI as long as the Java version supports HTTP or HTTPS protocols.
  public class URLScriptSourceProvider implements ScriptSourceProvider {
  public Reader getScriptSource(URI scriptUri) {
  if (scriptUri == null) {
  return null;
  }
  try {
  return new InputStreamReader(scriptUri.toURL().openStream())
  } 
  catch (MalformedURLException e) {
  return null;
  } 
  catch (IOException e) {
  return null;
  }
  }
}
Copy to Clipboard Toggle word wrap
In the META-INF directory of the script provider JAR, create a services directory.
Then, within the META-INF/services/ directory, create a file called org.rhq.scripting.ScriptSourceProvider. Put the full class names of any source providers implemented in the JAR, one per line. For example, if the URLScriptSourceProvider is the only source provider:
com.example.URLScriptSourceProvider
Copy to Clipboard Toggle word wrap
This is the layout of the JAR:
* com
* example 
* URLScriptSourceProvider.class
* META-INF 
* services 
* org.rhq.scripting.ScriptSourceProvider
Copy to Clipboard Toggle word wrap
This JAR must then ba added to the lib of the CLI installation directory. After that, scripts run through the JBoss ON CLI on that system can use the HTTP provider to download the file from the network:
var myModule = require("http://server.example.com/rhq-scripts/stuff.js");
Copy to Clipboard Toggle word wrap
For the same source provider to be available to alert scripts, the JAR needs to be added to the modules/org/rhq/server-startup/main/deployments/rhq.ear/lib/ directory of the JBoss ON server.
Retour au début
Red Hat logoGithubredditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

Theme

© 2025 Red Hat