Building a Java text editor
This step is for JBuilder Professional and Enterprise only.
Now that you've created the "Text Editor" application, you can deploy all the files to a Java Archive File (JAR) using JBuilder's Archive Builder.
samples/TextEditor
directory of your JBuilder installation. To do this, you need to convert the paths specified in the tutorial to point to samples/TextEditor
and its subdirectories.
This step of the tutorial will give you the explicit instructions for deploying the "Text Editor" application. It is not intended to be a comprehensive example of all the situations you will run across while deploying Java programs. Each application or applet you deploy has its own unique set of deployment issues, so it is difficult to generalize. Links are provided throughout this tutorial for further information on deployment, including Sun's JavaTM Tutorial.
The first step in deploying any program is to identify which project and library contents will be included in the archive. This will help you determine what classes and resources, as well as dependencies, to include. Including all classes, resources and dependencies in your archive creates a large archive file. However, the advantage is that you don't need to provide your end-user with other files as the archive contains everything needed to run the program. If you exclude some or all classes, resources or dependencies, you'll need to provide them to your end-user separately.
The Archive Builder will never include the JDK in your archive. It assumes that the JDK classes already exist on the target computer in the form of an installed JDK, Java runtime environment or Java Plug-in, or that you will be providing it in your installation.
JBuilder's Archive Builder also creates an archive node in your project, allowing easy access to the archive file. At any time during development, you can make the archive file, rebuild it, or reset its properties. You can also view the contents of the archive, as well as the contents of the manifest file.
Text Editor Application JAR
in the Name field. This is the name of the archive node that will be displayed in the project pane.
When you're done, Step 2 of the wizard should now look like this:
classes
directory of your project. For this tutorial, accept the default, so that the wizard includes all classes and resources on the outpath.
Step 3 of the wizard will look like this:
Step 4 of the wizard should look like this:
META-INF/MANIFEST.MF
. For more information on the manifest file, see "Understanding the Manifest" at http://java.sun.com/docs/books/tutorial/jar/basics/manifest.html".
Accept the default settings for Step 5 of the wizard. These options:
Step 5 of the wizard will look like this:
Step 6 of the wizard will look like this:
Text Editor Application JAR,
is now displayed in the project pane. You can right-click the archive node and make it, rebuild it, or change its properties.
TextEditor.jar.
Its contents are displayed in the structure pane and the contents of the manifest file are displayed in the content pane. JBuilder should now look similar to this:
Notice the following two headers in the manifest file:
Manifest-Version: 1.0
Main-Class: texteditor.TextEditClass
TextEditClass.class
is the entry point for your application (the class containing the public static void main(String[] args)
method, which runs the application.)
PATH
environment variable points to the JDK jre/bin directory, the runtime environment. The JBuilder installation process guarantees that JBuilder knows where to find the JDK class files. However, once you leave the JBuilder environment, your system needs to know where the class files for the Java runtime are installed. How you set the PATH
environment variable depends on which operating system you are using.
To run the Text Edit tutorial from the command line,
TextEditor
directory. This is where the JAR file is located.
java -jar TextEditor.jar
where,
java
- The Java tool that runs the jar file.
jar
- The option that tells the Java VM that the file is an archive file.
TextEditor.jar
- The name of the archive file.
Since the manifest file provides the information in the Main-Class header about which class to run, you don't need to specify the class name at the end of this command. And, because all classes, resources, and dependencies are included in the archived JAR file, you don't need to specify a classpath
or copy JBuilder libraries to this directory.
-jar
option, the Java runtime ignores any explicit classpath settings. If you try to run this JAR file when you're not in the TextEditor
directory, you need to use the following Java command:
java -jar -classpath <full_path>
<main_class_name>
The Java runtime looks in the JAR file for the startup class, and the other classes used by the application. The Java VM uses three search paths to look for the files: the bootstrap class path, the installed extensions, and the user class path. To learn about these search paths, see "How Classes Are Found" at http://java.sun.com/j2se/1.3/docs/tooldocs/findingclasses.html.
That's it! As you can see, there is a lot of information to assimilate related to deployment. Deployment goes far beyond just creating an archive file. Not only do you have to make sure you provide all the necessary classes and resources, as well as libraries, in your deployment set, you have be concerned with other issues, such as learning about the java tool and the Jar tool. There are also differences between running JDK 1.1 and Java 2 applications.
Take the time to study the wealth of information available at the links to Sun's web site provided here and in "Deploying Java programs" in Building Applications with JBuilder. You can also look at the Sun Tutorial trail on Jar files at http://java.sun.com/docs/books/tutorial/jar/index.html.
For suggestions on improving this tutorial, send email to jpgpubs@inprise.com.