When developing a program in Java, you sometimes need to use external resources that are not part of the language. For example, it is quite common to use images and audio clips in Java applets. VisualAge for Java does not store these external resources in the repository or workspace along with your Java source and byte codes. Instead you must create these resource files explicitly outside of the development environment and store them on the standard file system.
VisualAge for Java makes certain assumptions about where resource files are located. For a project called ProjectX, it assumes that the resource files will be found in a directory called IBMVJava\Ide\project_resources\ProjectX on the client machine (where IBMVJava is the install directory for the product). All projects in the workspace have a subdirectory of the project_resources directory, even if no resources have been created for the project.
Adding Resource Files to a Project
When you create a resource file, import it with the Import SmartGuide. This
will copy the resource file into a project's resources directory. From there, it
will be accessible to classes in that project.
Importing Packages the Have Resource Files
If you import a group of files from the file system, any non-.java, non-.class
files can be imported into the project resources directory. In the Import
SmartGuide, while importing files from the files system, enable the Resources option
and click Details to select which resource files to import.
Exporting Resources
When you export a project to a JAR file, resource files are exported to the JAR
file along with the classes. Also, when you select the Publish export option,
resource files can be exported along with the bytecode classes to the target directory.
Running Applets and Applications that Use Resources
When running an applet or application from within the IDE, the default CLASSPATH
contains the project resources directory so that it can find any resource files that the
program uses.
When running an applet from within the IDE, the code base for the applet is specified as the name of the resource directory. The URL of this directory will be returned by the java.applet.Applet.getCodeBase() method.
Shared
Resource Files
You can create a shared resources directory in addition to the local one, so that
all team members use the same copy of the resource file.
When you run an applet in the IDE, it looks for resource files first in the default location on the local file system, and second in the shared resource directory, if one is specified. When you export a resource files with classes, the local resource files are exported by default. For example, if the project has a resource file called picture.gif that exists in both local and shared resource directories, then the local one is exported, regardless of the timestamps on the files.
Java Methods that Get Resources
Use the following methods, or others like them, to get resource files into your
Java applets or applications:
See the related reference links below for API documentation for these classes.
Example
Applet COM.ibm.ivj.examples.awttests.AwtBlueGreenGem in project IBM Java Examples uses the file terre.gif and accesses it using getImage("terre.gif"). The default class path that VisualAge for Java uses to look for the file includes the project_resources\IBM Java Examples directory.
The default value for an applet's code base is the project_resources directory that corresponds to the applet's project.
The default value for a program's class path is the project_resources directory that corresponds to the program's project. As well, VisualAge for Java includes program/lib and program/lib/CLASSES.ZIP in the class path by default.
Importing Files from the File System
Exporting Code