VCF Automation Blog

from Stefan Schnell

Use Java Classes without Shutter File


These days I read an interesting old post about the com.vmware.scripting.javascript.allow-native-object property. Ilian Iliev wrotes: "This property is used to filter Java classes that are visible to scripts." The following logic shows that when this property is set to true, the ClassShutter has no effect. So I set this property in the Control Center and tested it.
The Control Center is called with the URL of the Orchestrator with a following /vco.
As far as I can tell, all classes are accepted when this property is set to true. This is a great thing, because on this way you can save to allow classes exactly, e.g. in test environments. That makes it much easier.

vcf automation control center property setting
com.vmware.scripting.javascript.allow-native-object

Addendum

The Control Center will no longer be available in future releases. To set a System Property it is necessary to use the vracli command with the vro parameter and the parameters below:
-k, –key: The name of the property to add. (Required)
-v, –value: The string value of the property to add. (Required)
-n, –noRestart: Whether modifying this property requires restart
                of the Orchestrator service.
                By default a restart is required. (Optional)

The following example demonstrates how to set a value of a property:
vracli vro properties set -k com.vmware.scripting.javascript.allow-native-object -v TRUE

To get the name, value and description of the most commonly used Orchestrator properties it is possible to use the following command:
vracli vro properties advanced

Get Available Packages

For example with the above setting the available packages can be detected.

var javaPackages = java.lang.Package.getPackages();
javaPackages.forEach( function(javaPackage) {
  System.log(
    javaPackage.getName() + ";" +
    javaPackage.getImplementationTitle() + ";" +
    javaPackage.getImplementationVendor() + ";" +
    javaPackage.getImplementationVersion() + ";" +
    javaPackage.getSpecificationTitle() + ";" +
    javaPackage.getSpecificationVendor() + ";" +
    javaPackage.getSpecificationVersion() + ";" +
    javaPackage.hashCode()
  );
});

Hint: The Java method getPackages returns all the Packages defined by the caller's class loader and its ancestors. The ClassLoader works dynamically. It is not required to submit in advance which classes the JVM can provide at runtime, because finding classes in a package is a file system operation. This means that they are not necessarily loaded at the start time, it can also be reloaded at runtime if required. This procedure can have the consequence that different classes being returned on identically installed systems.