Overview of Referenced FilesThis feature is useful when a component uses third-party tools that are not included directly in the component JAR file. If the referenced file is Java code, the system will automatically deploy the referenced file and add it to the classpath so that it can be used freely by the component. If two components use different versions of the same third-party tool, there is no conflict because each component will be loaded in its own classloader with its own version of dependent (referenced) tools. If a referenced file contains native (non-Java) code, the system will automatically deploy the native code file into a directory on the system PATH of the JVM. Deployment of the native code file allows the native code to be loaded using the System.loadLibrary() call without the native code knowing the full system-dependent path name of the file at compile time. The use of native code in a component imposes certain restrictions and limitations on the component. For more information, see Non-Java Code Considerations. The deployment descriptor tags to define a referenced file are <Requires> <Reference name="library_name_of_file" version="library_version_of_file" type="file_type" libname="native_file_name" platforms="platform_list" sharedloader="true|false" id="any_id"/> </Requires> The tags are as follows:
The name tag can contain the string {platform} if there are different versions of the file for different native platforms. For example, native code files are typically built for each platform, and the system must deploy the file that is correct for the platform on which the system is running. The {platform} string will be substituted at the time the component is loaded with one of the following values:
Likewise, if different versions of the file exist for different languages, the string {language} can be embedded in the name and will be resolved with an underscore followed by a 2-letter language identifier (e.g,. _en for US English, _ja for Japanese, etc.) Native Code Example<Requires> <Reference id="mylib" name="com.mycompany.mycomponent.my_c_code.{platform}" version="1.0.*" type="library" libname="myccode" platforms="Windows,Linux"/> </Requires> In this example, multiple copies of the file are published to the library, one for each supported platform (Windows and Linux). The library names will be: com.mycompany.mycomponent.my_c_code.win32 com.mycompany.mycomponent.my_c_code.Linux When the component is loaded into a model, the appropriate file is taken from the library and written to disk with a file name such as myccode.dll on Windows or libmyccode.50 on Linux. The file is placed in the JVM native code path, so that it can be loaded by the component by calling System.loadLibrary("myccode"). For more information about using native code, see Non-Java Code Considerations. Data File Example<Requires> <Reference id="mydata" name="com.mycompany.mycomponent.mydata" version="1.0.*" type="data" /> </Requires> This file will be read from the library and written to local disk when the component is loaded. The component can find this file by using the ID tag to locate it from the component’s MetaModel: MMReference ref = getMetaModel().getReference("mydata"); File myFile = ref.getLocalFile(); The File object can then be used to load the file content. Writing the file will update only the local deployed copy and may have undesirable side effects when the component is used in a parallel model or in the SIMULIA Execution Engine distributed shared environment. In general, components should not write to referenced files and should consider them read-only. |