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.
Viewing resource files inside the IDE
Project browsers have a Resources tab. To open a
project browser, double-click the project, or right-click the project and select Open
to > Resources. The Resources page provides a view of the disk on which
project resources are stored. The title bar above the resources view shows the name
of the directory that contains the resources (for example,
e:\IBMVJava\ide\project_resources\My Project). Expand the directory tree to view the
contents of the resources directory.
From within the project resources view, you can delete, rename, or open project resource files by using menu options in the Resource menu (or the pop-up menu). Creating, editing, copying, or moving resource files must be done outside the IDE in the file system.
Adding resource files to a project
When you create a resource file, import it with the Import
SmartGuide. Select Directory as the import source, select resource
as the file type, and specify the name of the target project. This will copy the resource
file into a project's resource directory. From there, it will be accessible to
classes in that project.
Importing packages that 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 file 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 resource 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 file 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 Examples directory called project_resources\IBM Java Examples.
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.
Resource files and directories
Importing files from the file system
Exporting code