Java Reference
In-Depth Information
Figure 19.1
Compile the Movie class using the -d flag.
When writing a class to represent a JavaBean, the class must be placed in a
JAR file along with a manifest file listing the contents of the JAR. There are sev-
eral steps involved in creating this JAR file, so let's work through them
together. Start by opening your text editor and following along with the ensu-
ing steps:
Step 1: Write the Bean Class
For this example, you will write and package the Movie bean class discussed
in the previous section. Type this Movie class into your text editor. Be sure to
compile it using the -d flag, as shown in Figure 19.1, because the Movie class is
in a package.
Step 2: Write the Manifest File
A manifest file is a text file that lists the files in a JAR. In many situations, the
manifest file is created for you automatically by the jar tool. However, when
using JavaBeans, you must write your own manifest file for the bean's JAR.
This manifest file needs to list which class files in the JAR are JavaBeans.
In our example, the JAR file will contain only one class: Movie.class.
Because this is a bean, we will denote the Java-Bean property of the file as True
in the manifest file, as shown in Figure 19.2. Type the file shown in Figure 19.2
in your text editor, and save it as movie.mf. Be sure to save it in the same direc-
tory as your file Movie.java.
Figure 19.2
Manifest file for the Movie bean (save it in a file named movie.mf).
Search WWH ::




Custom Search