Using the Java Archive Tool
By Mark Nesson
If you’re looking for an easy way to add .jar files to a WebFOCUS 5 .war file using Unix or DOS, I’ve got just the thing for you. In this article, I will go over several ways to do this.
But first, here’s a little background: The Java Archive Tool (JAR) utility is a JavaTM application that combines multiple files into a single JAR archive file. Based on the ZIP compression format, it is a general-purpose archiving and compression tool.
JAR was designed primarily for the packaging of Java applets or applications into a single archive file. When the components of an applet or application (.class files, .jar files, images and sounds) are combined into a single archive, users may download them through a Java agent, such
as a browser, in a single HTTP transaction, which means you don’t need a new connection for each piece.
Naturally, download times are therefore much shorter. JAR also compresses files, further improving download times. The syntax for the JAR tool is almost identical to the syntax for the TAR (tape archive) command.
Options
You can use an argument beginning with the character @ to specify a file containing additional arguments, one argument per line. These arguments are inserted into the command line at the position of the @<filename> argument. Here’s a list:
 |
c (creates a new or empty archive on the standard output) |
 |
t (lists the table of contents from standard output) |
 |
x file (extracts all files, or just the named files, from standard input if file is omitted, then all files are extracted; otherwise, only the specified file or files are extracted) |
 |
f (the second argument specifies a JAR file to process; in the case of creation, this refers to the name of the .jar file to be created, instead of on stdout for table or xtract, the second argument
identifies the jar file to be listed or extracted.) |
 |
v (generates verbose output on stderr) |
 |
m (includes manifest information from specified pre-existing manifest file)
|
Before we proceed, let’s look at some JAR file operations in the table shown in Figure 1.
| Operation |
Command |
| To create a JAR file |
jar cf jar-file input-file(s) |
| To view the contents of a JAR file |
jar tf jar-file |
| To extract the contents of a JAR file |
jar xf jar-file |
| To extract specific files from a JAR file |
jar xf jar-file archived-file(s) |
Figure 1
As an example, let’s say you need to look at the contents of the webfocus-5-2.war. You can do this by using WinZip or through the jar command.
With WinZip you can explode the contents of the .war file. Make sure you note the name and the path. This is key because if you want to add the .jar files for the Java Database Connectivity (JDBC) interface to access the SQL Server, they must be located in the relative path to the
.war file. That means you just can’t place the files anywhere (see Screen 1). So let’s add the SQL Server .jar files to .war file.

Screen 1
First open the .war file using WinZip. From any root directory, such as Mkdir C:\broarticle, change directory (cd) to c:\broarticle. Then create the directory:
mkdir WEB-INF
Cd c:\broarticle\WEB-INF
The next step is to create the subdirectory named library like so:
Mkdir lib
C:\broarticle\WEB-INF\lib
Then copy the three SQlL Server .jar files to this location so the contents of the directory look like this:
C:\broarticle\WEB-INF\lib
Msbase.jar
Mssqlserver.jar
Msutil.jar
Now using WinZip, let’s add them to the .war file. Click Add from the opened WinZip .war file. Change the directory to c:\broarticle. From the Add dialog, select or highlight WEB-INF, check Include Subfolders, then click Add with Wildcards. This process will add all the jars into the WEB-INF/lib directory in the webfocus5-2.war.
The three .jars are now added to the webfocus-5-2.war.
You may now re-deploy the .war file.
From DOS or the Unix command line, you want to see the contents of the webfocus-5-2.war. To accomplish this, I created a directory named c:\brotemp and added the webfocus-5-2.war to it. I then issued the following command:
C:\brotemp>jar tf webfocus-5-2.war >contentsofwar.txt
The contents are just like the directory structure if you go look at the C:\ibi\Web FOCUS52\webapps\webfocus-5-2.
Here’s an example of the contents of the contentsofwar.txt:
META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/classes/
WEB-INF/lib/
WEB-INF/lib/assist.jar
WEB-INF/lib/broker.jar
WEB-INF/lib/awt.jar
WEB-INF/lib/com.jar
WEB-INF/lib/beans.jar
WEB-INF/lib/edautil.jar
WEB-INF/lib/gen.jar
WEB-INF/lib/io.jar
WEB-INF/lib/javaassist.jar
WEB-INF/lib/jdbc.jar
WEB-INF/lib/jdbcx.jar
WEB-INF/lib/jlink.jar
WEB-INF/lib/meta-inf.jar
WEB-INF/lib/mrcgi.jar
From DOS, or Unix, I would create a directory and copy the webfocus-5-2.war into it by doing the following: Mkdir c:\brotemp
I would then look like the following: C:\brotemp\webfocus5-2.war
Under the brotemp directory, create the directory structure exactly like this:
Cd c:\brotemp
Mkdir WEB-INF
Cd to c:\brotemp\WEB-INF
Mkidr lib
Now copy the three SQL server .jar files to this directory:
C:\brotemp\WEB-INF\lib
Msbase.jar
Mssqlserver.jar
Msutil.jar
Go back to the c:\brotemp directory and issue this command:
C:\brotemp>jar uvf webfocus-5-2.war WEB- INF/lib/msbase.jar
adding:
WEB-INF/lib/msbase.jar(in = 286707) (out= 257540)(deflated 10%)
An even faster way is to add all the .jar files at once.
C:\brotemp>jar uvf webfocus-5-2.war WEB-
INF/lib/*.jar
adding: WEB-INF/lib/msbase.jar(in = 286707)
(out= 257540)(deflated 10%)
adding: WEB-INF/lib/mssqlserver.jar(in =
67024) (out= 61981)(deflated 7%)
adding: WEB-INF/lib/msutil.jar(in = 58903)
(out= 47394)(deflated 19%)
If you now issue the following command:
C:\brotemp>jar tf webfocus-5- 2.war >contentsofwar.txt
You will see that the contents is now contained the webfocus-5-2.war.
WEB-INF/lib/msbase.jar
WEB-INF/lib/mssqlserver.jar
WEB-INF/lib/msutil.jar
So, do you find this confusing? I thought you might, so I’ll show you an easier way to do it. Sit back relax and read on.
Copy the webfocus-5-2.war to a unique directory. In my example, I will use the directory structure C:\brotemp\wf52. Copy the to c:\brotemp so the contents look like C:\brotemp\webfocus5-2-.war.
Issue the following command:
C:\brotemp\wf52>jar -xvf ../webfocus-5-2.war .
By doing this, you are using the .jar command to extract all the files from the .war file, and it will build the correct directory and file structure under wf52.
So once the directories and files are expanded go to the WEB-INF\lib directory, add the .jar files you need for JDBC access. You may also add the db2java.zip for DB2 or whatever JDBC connection you decide to use for ReportCaster.
You may now call up the .jar the files up with the new JDBC .jars you just copied by doing the following:
C:\brotemp>jar cvf bro.war -C
c:\brotemp\wf52 .
In some instances, you may need to uncompress the .war file, in which case you would use the 0 (yes, zero) as part of the command. Take a look:
C:\brotemp>jar cv0f bro.war -C
c:\brotemp\wf52
To verify the compression, use WinZip and make a note of the ratio.
I’ve done my part. Now it’s your turn. Give this a try, and call me if you have any questions.
Java and all Java-based marks are trademarks of Sun Microsystems, Inc. in the U.S. and other countries.

|