Version 1.03, go to download
directly
Java Toolkit is a powerful java tool and an easy-to-use
software, which provides topmost supports for JDK tools and other popular tools.
It also contains unique tools created by us.
With assistances of the software, you can do many things you cannot do before.
Currently
the software contains nine java tools, followings are unique
abilities of
the software.
Javadoc
Automatically searches for java files.
Allows to encode java files in sub-directories.
Jar
Zip files
Allows to zip files in sub-directories or not.
Allows to include files by file types
Allows to exclude files by file extensions.
Unzip files
Allows to include files by file extensions
Allows to exclude files by file extensions.
Easy to extract specified files and directories from combrssed
file.
Keytool
Groups actions for easy using
Compulsory fields let you avoid mistakes
Convenient runtime responding makes things easier.
Javah
Automatically detects packages of class files
Stop feature checks for any mistakes
Displays full encoding information.
Javap
Automatically detects package of class file
Automatically separates classpath
Jarsigner
Enable and disable features make things easier
Error detections
Ant
Parsing build files as in place
Command are savable for reuse.
EXEs
Detects all tools available in JDK
Work-directory lets you execute all tools in places
All commands are savable.
Find
This tool is uniquely created by us, which is used for finding
classes, packages and checking classpath errors.
It contains 7 finding features:
exact classes, similar classes and multiple-used classes
multiple used full-qualified-classes
exact packages, Similar packages and multiple-used packages
The tool is very useful for java programmers, for example, you can use it
for designing package names to avoid mistakes.
You just need to simply click a tool on Sheet-bar (see picture 1), input options on
the tool's interface (see picture 2), then brss button Run on Work-bar to get
all you needed.
[Related readings]: basic knowledge of java tools.
javadoc - the java API documentation Generator
Command:
usage: javadoc [options] [packagenames] [sourcefiles] [@files]
-overview <file> Read overview documentation from HTML file
-public Show only public classes and members
-protected Show protected/public classes and members (default)
-package Show package/protected/public classes and members
-private Show all classes and members
-help Display command line options and exit
-doclet <class> Generate output via alternate doclet
-docletpath <path> Specify where to find doclet class files
-sourcepath <pathlist> Specify where to find source files
-classpath <pathlist> Specify where to find user class files
-exclude <pkglist> Specify a list of packages to exclude
-subpackages <subpkglist> Specify subpackages to recursively load
-breakiterator Compute 1st sentence with BreakIterator
-bootclasspath <pathlist> Override location of class files loaded
by the bootstrap class loader
-source <release> Provide source compatibility with specified
release
-extdirs <dirlist> Override location of installed extensions
-verbose Output messages about what Javadoc is doing
-locale <name> Locale to be used, e.g. en_US or en_US_WIN
-encoding <name> Source file encoding name
-quiet Do not display status messages
-J<flag> Pass <flag> directly to the runtime system
Provided by Standard doclet:
-d <directory> Destination directory for output files
-use Create class and package usage pages
-version Include @version paragraphs
-author Include @author paragraphs
-docfilessubdirs Recursively copy doc-file subdirectories
-splitindex Split index into one file per letter
-windowtitle <text> Browser window title for the documenation
-doctitle <html-code> Include title for the overview page
-header <html-code> Include header text for each page
-footer <html-code> Include footer text for each page
-bottom <html-code> Include bottom text for each page
-link <url> Create links to javadoc output at <url>
-linkoffline <url> <url2> Link to docs at <url> using
package list at <url2>
-excludedocfilessubdir <name1>:.. Exclude any doc-files
subdirectories with given name.
-group <name> <p1>:<p2>.. Group specified packages
together in overview page
-nocomment Supress description and tags, generate only declarations.
-nodeprecated Do not include @deprecated information
-noqualifier <name1>:<name2>:... Exclude the list of
qualifiers from the output.
-nosince Do not include @since information
-notimestamp Do not include hidden time stamp
-nodeprecatedlist Do not generate deprecated list
-notree Do not generate class hierarchy
-noindex Do not generate index
-nohelp Do not generate help link
-nonavbar Do not generate navigation bar
-serialwarn Generate warning about @serial tag
-tag <name>:<locations>:<header> Specify single
argument custom tags
-taglet The fully qualified name of Taglet to register
-tagletpath The path to Taglets
-charset <charset> Charset for cross-platform viewing of
generated documentation.
-helpfile <file> Include file that help link links to
-linksource Generate source in HTML
-sourcetab <tab length> Specify the number of spaces each tab
takes up in the source
-keywords Include HTML meta tags with package, class and member info
-stylesheetfile <path> File to change style of the generated
documentation
-docencoding <name> Output encoding name
jar - the java archive tool
Command:
Usage: jar {ctxu}[vfm0Mi] [jar-file] [manifest-file] [-C dir] files ...
Options:
-c create new archive
-t list table of contents for archive
-x extract named (or all) files from archive
-u update existing archive
-v generate verbose output on standard output
-f specify archive file name
-m include manifest information from specified manifest file
-0 store only; use no ZIP compression
-M do not create a manifest file for the entries
-i generate index information for the specified jar files
-C change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name and the archive file name needs to be specified
in the same order the 'm' and 'f' flags are specified.
Example 1: to archive two class files into an archive called
classes.jar:
jar cvf classes.jar Foo.class Bar.class
Example 2: use an existing manifest file 'mymanifest' and archive all
the
files in the foo/ directory into 'classes.jar':
jar cvfm classes.jar mymanifest -C foo/ .
Usage
Comparing to other format, compressed jar is platform independent
and compatible with popular operating systems, easy to be managed by
programmers, administrators, client, server, and in native, associate, appropriate architecture
with many benefits based on zlib algorithm.
Command:
Usage: javah [options] <classes>
where [options] include:
-help Print this help message and exit
-classpath <path> Path from which to load classes
-bootclasspath <path> Path from which to load bootstrap classes
-d <dir> Output directory
-o <file> Output file (only one of -d or -o may be used)
-jni Generate JNI-style header file (default)
-version Print version information
-verbose Enable verbose output
-force Always write output files
<classes> are specified with their fully qualified names (for
instance, java.lang.Object).
javap - the java class file dis-assembler (disassembles class files)
Command:
Usage: javap <options> <classes>...
where options include:
-c Disassemble the code
-classpath <pathlist> Specify where to find user class files
-extdirs <dirs> Override location of installed extensions
-help Print this usage message
-J<flag> Pass <flag> directly to the runtime system
-l Print line number and local variable tables
-public Show only public classes and members
-protected Show protected/public classes and members
-package Show package/protected/public classes
and members (default)
-private Show all classes and members
-s Print internal type signatures
-bootclasspath <pathlist> Override location of class files loaded
by the bootstrap class loader
-verbose Print stack size, number of locals and args for methods
If verifying, print reasons for failure
jarsigner - jar signing and verification tool
Command:
Usage: jarsigner [options] jar-file alias
jarsigner -verify [options] jar-file
[-keystore <url>] keystore location
[-storepass <password>] password for keystore integrity
[-storetype <type>] keystore type
[-keypass <password>] password for private key (if different)
[-sigfile <file>] name of .SF/.DSA file
[-signedjar <file>] name of signed JAR file
[-verify] verify a signed JAR file
[-verbose] verbose output when signing/verifying
[-certs] display certificates when verbose and verifying
[-tsa <url>] location of the Timestamping Authority
[-tsacert <alias>] public key certificate for Timestamping
Authority
[-altsigner <class>] class name of an alternative signing
mechanism
[-altsignerpath <pathlist>] location of an alternative signing
mechanism
[-internalsf] include the .SF file inside the signature block
[-sectionsonly] don't compute hash of entire manifest
[-protected] keystore has protected authentication path
[-providerName <name>] provider name
[-providerClass <class> name of cryptographic service provider's
[-providerArg <arg>]] ... master class file and constructor
argument
Description
The jarsigner tool is used for two purposes:
to sign Java ARchive (JAR) files, and
to verify the signatures and integrity of signed JAR files.
The JAR feature enables the packaging of class files, images, sounds, and
other digital data in a single file for faster and easier distribution. A tool
named
jar
enables developers to produce JAR files. (Technically, any zip file can also
be considered a JAR file, although when created by jar or processed by
jarsigner, JAR files also contain a META-INF/MANIFEST.MF file.)
A digital signature is a string of bits that is computed from some data
(the data being "signed") and the private key of an entity (a
person, company, etc.). Like a handwritten signature, a digital signature has
many useful characteristics:
Its authenticity can be verified, via a computation that uses the public
key corresponding to the private key used to generate the signature.
It cannot be forged, assuming the private key is kept secret.
It is a function of the data signed and thus can't be claimed to be the
signature for other data as well.
The signed data cannot be changed; if it is, the signature will no
longer verify as being authentic.
In order for an entity's signature to be generated for a file, the entity
must first have a public/private key pair associated with it, and also one or
more certificates authenticating its public key. A certificate is a digitally
signed statement from one entity, saying that the public key of some other
entity has a particular value.
jarsigner uses key and certificate information from a keystore to generate
digital signatures for JAR files. A keystore is a database of private keys and
their associated X.509 certificate chains authenticating the corresponding
public keys. The
keytool
utility is used to create and administer keystores.
jarsigner uses an entity's private key to generate a signature. The signed
JAR file contains, among other things, a copy of the certificate from the
keystore for the public key corresponding to the private key used to sign the
file. jarsigner can verify the digital signature of the signed JAR file using
the certificate inside it (in its signature block file).
At this time, jarsigner can only sign JAR files created by the JDK
jar
tool or zip files. (JAR files are the same as zip files, except they also have
a META-INF/MANIFEST.MF file. Such a file will automatically be created when
jarsigner signs a zip file.)
The default jarsigner behavior is to sign a JAR (or zip) file. Use the -verify
option to instead have it verify a signed JAR file.
Compatibility with JDK 1.1
The keytool and jarsigner tools completely replace the javakey tool
provided in JDK 1.1. These new tools provide more features than javakey,
including the ability to protect the keystore and private keys with
passwords, and the ability to verify signatures in addition to generating
them.
The new keystore architecture replaces the identity database that javakey
created and managed. There is no backwards compatibility between the
keystore format and the database format used by javakey in 1.1. However,
It is possible to import the information from an identity database
into a keystore, via a keytool command.
Jarsigner can sign JAR files also previously signed using javakey.
jarsigner can verify JAR files signed using javakey. Thus, it
recognizes and can work with signer aliases that are from a JDK 1.1
identity database rather than a JDK 1.2 keystore.
Keystore Aliases
All keystore entities are accessed via unique aliases.
When using jarsigner to sign a JAR file, you must specify the alias for
the keystore entry containing the private key needed to generate the
signature. For example, the following will sign the JAR file named "MyJarFile.jar",
using the private key associated with the alias "duke" in the
keystore named "mystore" in the "working" directory.
Since no output file is specified, it overwrites MyJarFile.jar with the
signed JAR file.
jarsigner -keystore /working/mystore -storepass
myspass
-keypass dukekeypasswd MyJarFile.jar duke
Keystores are protected with a password, so the store password (in this
case "myspass") must be specified. You will be prompted for it if
you don't specify it on the command line. Similarly, private keys are
protected in a keystore with a password, so the private key's password (in
this case "dukekeypasswd") must be specified, and you will be
prompted for it if you don't specify it on the command line and it isn't the
same as the store password.
Keystore Location
jarsigner has a -keystore option for specifying the URL of the
keystore to be used. The keystore is by default stored in a file named .keystore
in the user's home directory, as determined by the "user.home"
system property. On Solaris systems "user.home" defaults to the
user's home directory.
Keystore Implementation
The KeyStore class provided in the java.security
package supplies well-defined interfaces to access and modify the
information in a keystore. It is possible for there to be multiple different
concrete implementations, where each implementation is that for a particular
type of keystore.
Currently, there are two command-line tools that make use of keystore
implementations (keytool and jarsigner), and also a GUI-based tool named
policytool. Since KeyStore is publicly available, JDK users can
write additional security applications that use it.
There is a built-in default implementation, provided by Sun Microsystems.
It implements the keystore as a file, utilizing a proprietary keystore type
(format) named "JKS". It protects each private key with its
individual password, and also protects the integrity of the entire keystore
with a (possibly different) password.
Keystore implementations are provider-based. More specifically, the
application interfaces supplied by KeyStore are implemented in
terms of a "Service Provider Interface" (SPI). That is, there is a
corresponding abstract KeystoreSpi class, also in the java.security
package, which defines the Service Provider Interface methods that
"providers" must implement. (The term "provider" refers
to a package or a set of packages that supply a concrete implementation of a
subset of services that can be accessed by the Java Security API.) Thus, to
provide a keystore implementation, clients must implement a
"provider" and supply a KeystoreSpi subclass implementation, as
described in
How
to Implement a Provider for the Java Cryptography Architecture.
Applications can choose different types of keystore implementations from
different providers, using the "getInstance" factory method
supplied in the KeyStore class. A keystore type defines the
storage and data format of the keystore information, and the algorithms used
to protect private keys in the keystore and the integrity of the keystore
itself. Keystore implementations of different types are not compatible. The
keytool, jarsigner, and policytool tools can be used with any type of
keystore, because they only use the common application interfaces supplied
by KeyStore.
The tools currently choose a keystore implementation based simply on the
value of the keystore.type property specified in the security
properties file. The security properties file is called
java.security
,
and it resides in the JDK security properties directory, java.home/lib/security,
where java.home is the JDK installation directory.
Each tool gets the keystore.type value and then examines all
the currently-installed providers until it finds one that implements
keystores of that type. It then uses the keystore implementation from that
provider.
The KeyStore class defines a static method named getDefaultType
that lets applications and applets retrieve the value of the keystore.type
property. The following line of code creates an instance of the default
keystore type (as specified in the keystore.type property):
KeyStore keyStore =
KeyStore.getInstance(KeyStore.getDefaultType());
The default keystore type is "jks" (the proprietary type of the
keystore implementation provided by Sun). This is specified by the following
line in the security properties file:
keystore.type=jks
To have the tools utilize a keystore implementation other than the
default, change that line to specify a different keystore type.
For example, if you have a provider package that supplies a keystore
implementation for a keystore type called "pkcs12", change the
line to
keystore.type=pkcs12
Note: case doesn't matter in keystore type designations. For example, "JKS"
would be considered the same as "jks".
Alternatively, for keytool, you can specify a keystore type at the
command line, via the -storetype option; and for policytool, you can specify
a keystore type via the "Change Keystore" command in the Edit
menu.
Supported Algorithms and Key Sizes
At this time, jarsigner can sign a JAR file using either
DSA (Digital Signature Algorithm) with the SHA-1 digest algorithm, or
the RSA algorithm with the MD5 digest algorithm.
That is, if the signer's public and private keys are DSA keys, jarsigner
will sign the JAR file using the "SHA1withDSA" algorithm. If the
signer's keys are RSA keys, jarsigner will sign the JAR file using the
"MD5withRSA" algorithm. This is only possible if there is a
statically installed
provider
supplying an implementation for the "MD5withRSA" algorithm. (There
is always a "SHA1withDSA" algorithm available, from the default
"SUN" provider.)
The Signed JAR File
When jarsigner is used to sign a JAR file, the output signed JAR file is
exactly the same as the input JAR file, except that it has two additional
files placed in the META-INF directory:
a signature file, with a .SF extension, and
a signature block file, with a .DSA extension.
The base file names for these two files come from the value of the -sigFile
option. For example, if the option appears as
-sigFile MKSIGN
the files are named "MKSIGN.SF" and "MKSIGN.DSA".
If no -sigfile option appears on the command line, the base
file name for the .SF and .DSA files will be the first 8 characters of the
alias name specified on the command line, all converted to upper case. If
the alias name has fewer than 8 characters, the full alias name is used. If
the alias name contains any characters that are not legal in a signature
file name, each such character is converted to an underscore ("_")
character in forming the file name.
The Signature (.SF) File
A signature file (the .SF file) looks similar to the manifest file that is
always included in a JAR file when jarsigner is used to sign the file.
That is, for each source file included in the JAR file, the .SF file has
three lines, just as in the manifest file, listing the following:
the file name,
the name of the digest algorithm used (SHA), and
a SHA digest value.
In the manifest file, the SHA digest value for each source file is the
digest (hash) of the binary data in the source file. In the .SF file, on
the other hand, the digest value for a given source file is the hash of
the three lines in the manifest file for the source file.
The signature file also, by default, includes a header containing a
hash of the whole manifest file. The presence of the header enables
verification optimization, as described in
JAR File
Verification.
The Signature Block (.DSA) File
The .SF file is signed and the signature is placed in the .DSA file. The .DSA
file also contains, encoded inside it, the certificate or certificate
chain from the keystore which authenticates the public key corresponding
to the private key used for signing.
JAR File Verification
A successful JAR file verification occurs if the signature(s) are valid,
and none of the files that were in the JAR file when the signatures were
generated have been changed since then. JAR file verification involves the
following steps:
Verify the signature of the .SF file itself.
That is, the verification ensures that the signature stored in each
signature block (.DSA) file was in fact generated using the private key
corresponding to the public key whose certificate (or certificate chain)
also appears in the .DSA file. It also ensures that the signature is a
valid signature of the corresponding signature (.SF) file, and thus the
.SF file has not been tampered with.
Verify the digest listed in each entry in the .SF file with each
corresponding section in the manifest.
The .SF file by default includes a header containing a hash of the
entire manifest file. When the header is present, then the verification
can check to see whether or not the hash in the header indeed matches
the hash of the manifest file. If that is the case, verification
proceeds to the next step.
If that is not the case, a less optimized verification is required to
ensure that the hash in each source file information section in the .SF
file equals the hash of its corresponding section in the manifest file
(seeThe Signature (.SF) File).
One reason the hash of the manifest file that is stored in the .SF
file header may not equal the hash of the current manifest file would be
because one or more files were added to the JAR file (using the jar
tool) after the signature (and thus the .SF file) was generated. When
the jar tool is used to add files, the manifest file is
changed (sections are added to it for the new files), but the .SF file
is not. A verification is still considered successful if none of the
files that were in the JAR file when the signature was generated have
been changed since then, which is the case if the hashes in the
non-header sections of the .SF file equal the hashes of the
corresponding sections in the manifest file.
Read each file in the JAR file that has an entry in the .SF file.
While reading, compute the file's digest, and then compare the result
with the digest for this file in the manifest section. The digests
should be the same, or verification fails.
If any serious verification failures occur during the verification
process, the process is stopped and a security exception is thrown. It is
caught and displayed by jarsigner.
Multiple Signatures for a JAR File
A JAR file can be signed by multiple people simply by running the jarsigner
tool on the file twice, specifying the alias for a different person each
time, as in:
jarsigner myBundle.jar susan
jarsigner myBundle.jar kevin
When a JAR file is signed multiple times, there are multiple .SF and .DSA
files in the resulting JAR file, one pair for each signature. Thus, in the
example above, the output JAR file includes files with the following names:
SUSAN.SF
SUSAN.DSA
KEVIN.SF
KEVIN.DSA
Note: It is also possible for a JAR file to have mixed signatures, some
generated by the JDK 1.1 javakey tool and others by jarsigner. That is,
jarsigner can be used to sign JAR files already previously signed using
javakey.
OPTIONS
The various jarsigner options are listed and described below. Note:
All option names are preceded by a minus sign (-).
The options may be provided in any order.
Items in italics (option values) represent the actual values that must
be supplied.
The -keystore, -storepass, -keypass,
-sigfile , and -signedjar options are only
relevant when signing a JAR file, not when verifying a signed JAR file.
Similarly, an alias is only specified on the command line when signing a
JAR file.
-keystore url
Specifies the URL that tells the keystore location. This defaults to the
file .keystore in the user's home directory, as determined by the "user.home"
system property.
A keystore is required when signing, so you must explicitly specify one
if the default keystore does not exist (or you want to use one other than
the default).
A keystore is not required when verifying, but if one is specified, or
the default exists, and the -verbose option was also
specified, additional information is output regarding whether or not any
of the certificates used to verify the JAR file are contained in that
keystore.
Note: the -keystore argument can actually be a file name
(and path) specification rather than a URL, in which case it will be
treated the same as a "file:" URL. That is,
-keystore filePathAndName
is treated as equivalent to
-keystore file:filePathAndName
-storepass password
Specifies the password which is required to access the keystore. This is
only needed when signing (not verifying) a JAR file. In that case, if a -storepass
option is not provided at the command line, the user is prompted for the
password.
Note: The password shouldn't be specified on the command line or in a
script unless it is for testing purposes, or you are on a secure system.
Also, when typing in a password at the password prompt, the password is
echoed (displayed exactly as typed), so be careful not to type it in front
of anyone.
-keypass password
Specifies the password used to protect the private key of the keystore
entry addressed by the alias specified on the command line. The password
is required when using jarsigner to sign a JAR file. If no password is
provided on the command line, and the required password is different from
the store password, the user is prompted for it.
Note: The password shouldn't be specified on the command line or in a
script unless it is for testing purposes, or you are on a secure system.
Also, when typing in a password at the password prompt, the password is
echoed (displayed exactly as typed), so be careful not to type it in front
of anyone.
-sigfile file
Specifies the base file name to be used for the generated .SF and .DSA
files. For example, if file is "DUKESIGN", the generated .SF and
.DSA files will be named "DUKESIGN.SF" and "DUKESIGN.DSA",
and will be placed in the "META-INF" directory of the signed JAR
file.
The characters in file must come from the set "A-Z0-9_-".
That is, only letters, numbers, underscore, and hyphen characters are
allowed.
If no -sigfile option appears on the command line, the
base file name for the .SF and .DSA files will be the first 8 characters
of the alias name specified on the command line, all converted to upper
case. If the alias name has fewer than 8 characters, the full alias name
is used. If the alias name contains any characters that are not legal in a
signature file name, each such character is converted to an underscore
("_") character in forming the file name.
-signedjar file
Specifies the name to be used for the signed JAR file.
If no name is specified on the command line, the name used is the same
as the input JAR file name (the name of the JAR file to be signed); in
other words, that file is overwritten with the signed JAR file.
-verify
If this appears on the command line, the specified JAR file will be
verified, not signed. If the verification is successful, "jar
verified" will be displayed. If you try to verify an unsigned JAR
file, or a JAR file signed with an unsupported algorithm (e.g., RSA when
you don't have an RSA provider installed), the following is displayed:
"jar is unsigned. (signatures missing or not parsable)"
It is possible to verify JAR files signed using either jarsigner or the
JDK 1.1 javakey tool, or both.
For further information on verification, see
JAR
File Verification
-certs
If this appears on the command line, along with the -verify
and -verbose options, the output includes certificate
information for each signer of the JAR file. This information includes
the name of the type of certificate (stored in the .DSA file) that
certifies the signer's public key,
if the certificate is an X.509 certificate (more specifically, an
instance of java.security.cert.X509Certificate): the
distinguished name of the signer, and
in parentheses, the alias name for the keystore entry (if any) for
that signer. If the signer actually comes from a JDK 1.1 identity
database instead of from a keystore, the alias name will appear in
brackets instead of parentheses.
-verbose
If this appears on the command line, it indicates "verbose"
mode, which causes jarsigner to output extra information as to the
progress of the JAR signing or verification.
-internalsf
In the past, the .DSA (signature block) file generated when a JAR file
was signed used to include a complete encoded copy of the .SF file
(signature file) also generated. This behavior has been changed. To reduce
the overall size of the output JAR file, the .DSA file by default doesn't
contain a copy of the .SF file anymore. But if -internalsf
appears on the command line, the old behavior is utilized. This option is
mainly useful for testing; in practice, it should not be used, since doing
so eliminates a useful optimization.
-sectionsonly
If this appears on the command line, the .SF file (signature file)
generated when a JAR file is signed does not include a header containing a
hash of the whole manifest file. It just contains information and hashes
related to each individual source file included in the JAR file, as
described in
The Signature (.SF) File.
By default, this header is added, as an optimization. When the header
is present, then whenever the JAR file is verified, the verification can
first check to see whether or not the hash in the header indeed matches
the hash of the whole manifest file. If so, verification proceeds to the
next step. If not, it is necessary to do a less optimized verification
that the hash in each source file information section in the .SF file
equals the hash of its corresponding section in the manifest file.
For further information, see
JAR File Verification.
This option is mainly useful for testing; in practice, it should not be
used, since doing so eliminates a useful optimization.
-Jjavaoption
Passes through the specified javaoption string directly to the Java
interpreter. (jarsigner is actually a "wrapper" around the
interpreter.) This option should not contain any spaces. It is useful for
adjusting the execution environment or memory usage. For a list of
possible interpreter options, type java -h or java -X
at the command line.
EXAMPLES
Signing a JAR File
Suppose you have a JAR file named "bundle.jar" and you'd like
to sign it using the private key of the user whose keystore alias is "jane"
in the keystore named "mystore" in the "working"
directory. Suppose the keystore password is "myspass" and the
password for jane's private key is "j638klm". You can use the
following to sign the JAR file and name the signed JAR file "sbundle.jar":
jarsigner -keystore /working/mystore -storepass
myspass
-keypass j638klm -signedjar sbundle.jar
bundle.jar jane
Note that there is no -sigfile specified in the command
above, so the generated .SF and .DSA files to be placed in the signed JAR
file will have default names based on the alias name. That is, they will be
named JANE.SF and JANE.DSA.
If you want to be prompted for the store password and the private key
password, you could shorten the above command to
jarsigner -keystore /working/mystore
-signedjar sbundle.jar bundle.jar jane
If the keystore to be used is the default keystore (the one named ".keystore"
in your home directory), you don't need to specify a keystore, as in:
jarsigner -signedjar sbundle.jar bundle.jar jane
Finally, if you want the signed JAR file to simply overwrite the input JAR
file (bundle.jar), you don't need to specify a -signedjar
option:
jarsigner bundle.jar jane
Verifying a Signed JAR File
To verify a signed JAR file, that is, to verify that the signature is valid
and the JAR file has not been tampered with, use a command such as the
following:
jarsigner -verify sbundle.jar
If the verification is successful,
jar verified.
is displayed. Otherwise, an error message appears.
You can get more information if you use the -verbose option.
A sample use of jarsigner with the -verbose option is shown
below, along with sample output:
jarsigner -verify -verbose sbundle.jar
198 Fri Sep 26
16:14:06 PDT 1997 META-INF/MANIFEST.MF
199 Fri Sep 26
16:22:10 PDT 1997 META-INF/JANE.SF
1013 Fri Sep 26
16:22:10 PDT 1997 META-INF/JANE.DSA
smk 2752 Fri Sep 26 16:12:30 PDT 1997
AclEx.class
smk 849 Fri Sep 26 16:12:46 PDT 1997
test.class
s = signature was verified
m = entry is listed in manifest
k = at least one certificate was found in
keystore
jar verified.
Verification with Certificate Information
If you specify the -certs option when verifying, along with the
-verify and -verbose options, the output includes
certificate information for each signer of the JAR file, including the
certificate type, the signer distinguished name information (iff it's an
X.509 certificate), and, in parentheses, the keystore alias for the signer.
For example,
jarsigner -verify -verbose -certs myTest.jar
198 Fri Sep 26
16:14:06 PDT 1997 META-INF/MANIFEST.MF
199 Fri Sep 26
16:22:10 PDT 1997 META-INF/JANE.SF
1013 Fri Sep 26
16:22:10 PDT 1997 META-INF/JANE.DSA
208 Fri Sep 26
16:23:30 PDT 1997 META-INF/JAVATEST.SF
1087 Fri Sep 26
16:23:30 PDT 1997 META-INF/JAVATEST.DSA
smk 2752 Fri Sep 26 16:12:30 PDT 1997
Tst.class
X.509, CN=Test Group, OU=Java Software, O=Sun
Microsystems, L=CUP, S=CA, C=US (javatest)
X.509, CN=Jane Smith, OU=Java Software,
O=Sun, L=cup, S=ca, C=us (jane)
s = signature was verified
m = entry is listed in manifest
k = at least one certificate was found in
keystore
jar verified.
If the certificate for a signer is not an X.509 certificate, there is no
distinguished name information. In that case, just the certificate type and
the alias are shown. For example, if the certificate is a PGP certificate,
and the alias is "bob", you'd get
PGP, (bob)
Verification of a JAR File that Includes Identity Database Signers
If a JAR file has been signed using the JDK 1.1 javakey tool, and thus the
signer is an alias in an identity database, the verification output includes
an "i" symbol. If the JAR file has been signed by both an alias in
an identity database and an alias in a keystore, both "k" and
"i" appear.
When the -certs option is used, any identity database
aliases are shown in square brackets rather than the parentheses used for
keystore aliases. For example:
jarsigner -verify -verbose -certs writeFile.jar
198 Fri Sep 26
16:14:06 PDT 1997 META-INF/MANIFEST.MF
199 Fri Sep 26
16:22:10 PDT 1997 META-INF/JANE.SF
1013 Fri Sep 26
16:22:10 PDT 1997 META-INF/JANE.DSA
199 Fri Sep 27
12:22:30 PDT 1997 META-INF/DUKE.SF
1013 Fri Sep 27
12:22:30 PDT 1997 META-INF/DUKE.DSA
smki 2752 Fri Sep 26 16:12:30 PDT 1997
writeFile.html
X.509, CN=Jane Smith, OU=Java Software,
O=Sun, L=cup, S=ca, C=us (jane)
X.509, CN=Duke, OU=Java Software, O=Sun,
L=cup, S=ca, C=us [duke]
s = signature was verified
m = entry is listed in manifest
k = at least one certificate was found in
keystore
i = at least one certificate was found in
identity scope
jar verified.
Note that the alias "duke" is in brackets to denote that it is an
identity database alias, not a keystore alias.
Ant - Java based build tool
Command:
Options:
-help, -h print this message
-projecthelp, -p print project help information
-version print the version information and exit
-diagnostics print information that might be helpful to
diagnose or report problems.
-quiet, -q be extra quiet
-verbose, -v be extra verbose
-debug, -d print debugging information
-emacs, -e produce logging information without adornments
-lib <path> specifies a path to search for jars and classes
-logfile <file> use given file for log
-l <file> ''
-logger <classname> the class which is to perform logging
-listener <classname> add an instance of class as a project
listener
-noinput do not allow interactive input
-buildfile <file> use given buildfile
-file <file> ''
-f <file> ''
-D<property>=<value> use value for given property
-keep-going, -k execute all targets that do not depend
on failed target(s)
-propertyfile <name> load all properties from file with -D
properties taking precedence
-inputhandler <class> the class which will handle input requests
-find <file> (s)earch for buildfile towards the root of
-s <file> the filesystem and use it
-nice number A niceness value for the main thread:
1 (lowest) to 10 (highest); 5 is the default
-nouserlib Run ant without using the jar files from
${user.home}/.ant/lib
-noclasspath Run ant without using CLASSPATH
Intruduction
Ant is a Java based build tool, similar to make, but with better support
for the cross platform issues involved with developing Java applications.
Ant is the build tool of choice for all Java projects at Apache and many
other Open Source Java projects. Ant can be configured to compile your
java source code files, build your deployment JAR and WAR files, unit-test
code and create projects javadoc documentation.
Ant 1.6.0
adds a lot of new features, most prominently support for XML namespaces as
well as a new concept of Ant libraries that makes use of namespaces to
avoid name clashes of custom tasks.
Advantages of Ant
Build
IN Java, USING Java, and FOR Java
Supports
Java Tools (javac, javadoc, etc.)
XML
Build File is Easier to Build, Read, and Maintain than MAKE
file
Easier
to Extend
Supports
Cross Platform Java Development
Ant
is much faster than using MAKE ? Each command is a new process
Ant
runs within the JVM
Each
command is executed from within JVM
Tools
like javac are new threads ?not new process
Compiling
large number of java source files is MUCH,MUCH faster with Ant
Ant's
Debug Options are very helpful
XML
much easier to read than MAKEFILE
User
does not need to know all command line interface options to
tools that can be called programmatically
Even
OS-Specific commands can be setup in 'TaskDefs' and/or
included from other sources
Installing Ant
Regardless
of platform, downloading Ant is the first step to installing the
software. The files can be downloaded to a temporary directory and
then uncompressed to any desired directory. After the download step,
the process differs depending on whether you've downloaded the
binary distribution or the source distribution.
Ant does not provide an installation program; it runs from wherever
you choose to copy the files and directories. Lists the directories
that ultimately get created under your main Ant directory.
Directories provided with Ant bin - Batch files, Perl scripts, and shell
scripts for running Ant. docs - Ant documentation. lib - Libraries required by Ant to run. src - Source code for Ant. Provided only
in the source distribution.
Binary Installation The term "binary" just means that everything is
compiled and packaged into JAR files for easy execution ?you
don't need to compile Ant from source.
Steps to install Installation of the binary distribution:
1. Unzip (or untar) the distribution to the desired directory.
2. Set the ANT_HOME environment variable to point to to the ant
installation directory.
3. Set the JAVA_HOME environment variable to point to the JDK
location.
4. Add ANT_HOME/bin to your system's PATH environment variable.
The ant script uses the ANT_HOME and JAVA_HOME environment variables
to configure the CLASSPATH used by the JVM running Ant. If these
variables are not set, the startup script attempts to infer the
correct values, subject to operating system limitations.
Source Installation Installing the Ant source distribution requires a little
more work than installing the binary distribution. As expected,
downloading and uncompressing the distribution is the first step.
You generally want to place the source files in a directory separate
from any existing Ant installations. Next, ensure that JAVA_HOME
points to the JDK distribution. As with the binary installation, you
should also set ANT_HOME and update your PATH.
type the following command from the source distribution directory:
build
-Ddist.dir=destination_directory dist (Windows)
build.sh -Ddist.dir=destination_directory dist (Unix)
The build script creates a complete binary distribution of Ant
in the specified destination directory. When omitted, dist.dir
defaults to build.
Ant
Basics Each
'Project' has a Build File, Default build file name is 'build.xml',
Can Specify any name with '-buildfile' command line
option, Ant's buildfiles are written in XML.
The
first or root element of any buildfile is always the <project>
tag. No buildfile can be without one nor can it have more than one.
<project
name="MyProject" default="all" basedir=".">
</project>
The <project> tag has three attributes: name,
default, and basedir.
The
name attribute gives the project a name.
The
default attribute refers to a target name within the
buildfile. If you run Ant without specifying a target on
the command line, Ant executes the default target. If
the default target doesn't exist, Ant returns an error.
The
basedir attribute defines the root directory of a
project. Typically, it is ".", the directory
in which the buildfile resides, regardless of the
directory you're in when you run Ant. However, basedir
can also define different points of reference.
Each
buildfile contains one project and at least one (default) target.
Examples are: 'compile', 'test', 'install', 'clean', etc.
Apache Ant Apache Ant is a Java-based build tool. In theory, it is kind of like
Make, but without Make's wrinkles.
Why another build tool when there is already make, gnumake, nmake, jam, and others? Because all those tools have
limitations that Ant's original author couldn't live with when developing
software across multiple platforms. Make-like tools are inherently
shell-based -- they evaluate a set of dependencies, then execute commands
not unlike what you would issue in a shell. This means that you can easily
extend these tools by using or writing any program for the OS that you are
working on. However, this also means that you limit yourself to the OS, or
at least the OS type such as Unix, that you are working on.
Makefiles are inherently evil as well. Anybody who has worked on them
for any time has run into the dreaded tab problem. "Is my command not
executing because I have a space in front of my tab!!!" said the
original author of Ant way too many times. Tools like Jam took care of
this to a great degree, but still have yet another format to use and
remember.
Ant is different. Instead of a model where it is extended with
shell-based commands, Ant is extended using Java classes. Instead of
writing shell commands, the configuration files are XML-based, calling out
a target tree where various tasks get executed. Each task is run by an
object that implements a particular Task interface.
Granted, this removes some of the expressive power that is inherent by
being able to construct a shell command such as `find . -name foo
-exec rm {}`, but it gives you the ability to be cross platform --
to work anywhere and everywhere. And hey, if you really need to execute a
shell command, Ant has an <exec> task that allows
different commands to be executed based on the OS that it is executing on.
Concepts, article, informationContents
Developing in a Standard Directory Tree
Creating
Standard Ant Targets and What They Should Do
Exploring
Ant Data Types
Listeners
and Loggers
Predefined
Properties
The
Ant Command Line
Summary
Article Description
Joey Gibson, Kirk Pepperdine, Alan Williamson, and Andrew Wu study of
a useful standard development directory tree, cover the basic targets
of almost every Ant build file, data types, listeners and loggers, and
the Ant command line.
We'll begin this chapter with a description of a standard
development directory structure. We'll show you what is generally used
for different types of projects and explain why you should consider
adopting it for your own projects.
What we'll be showing you is a common structure, but there are
other layouts that you may choose to use. Ant makes it easy to work
with just about any layout you can dream up.
We'll then move on to more "standard" stuff. In this
case, it's a discussion of what to call your targets. There are
certain targets that just about every build file you run across will
contain, and there are others that just make good sense. We'll discuss
all of these.
Next, we'll discuss what are known as Ant data types
including tags to generate sets of files matching certain criteria,
path-like structures, and filters.
Moving on, we'll cover loggers and listeners. These facilities
provide the capability to control how your builds are logged (loggers)
and to trigger behavior when certain lifecycle events occur
(listeners).
Finally, we will discuss those properties that are defined
automatically by Ant, how they are useful, and the command line
arguments that Ant accepts.
Unlike most of the other chapters in this book, there are no Java
source files that can be downloaded from the publisher's Web site,
nor is there a working build file. The reason for this is the sheer
volume of topics that will be covered and the near impossibility of
devising a project incorporating all of them. You can, however,
download a build file that contains each of the Ant snippets that
will be presented so that you can paste them in to your own build
files. This file won't be able to run by itself. Just think of it as
a snippet repository.
Developing in a Standard Directory Tree With a title like that for this section, you're probably thinking
this sounds about as exciting as reading a dictionary, but hold on!
This is stuff you need to know. In this section, we'll to cover a
standard directory tree structure for your projects. Obviously, there
isn't actually a standard for this type of thing yet, but this is a
good starting point.Directory Tree for Simple Projects Let's begin by talking about the base structure for any type of
project and then move into Web applications. For most applications,
you'll have source code (otherwise, why would you need Ant?) that must
be compiled, and you'll also have .class files that must go
somewhere. You'll (probably) create some sort of archive file and it
must live somewhere. If you're running unit tests on your code (you
are, aren't you?), you'll want to store the output and subsequent
reports someplace as well. If you use a custom MANIFEST.MF
file, you'll want to store it somewhere, too. All these files and
directories should live under a project directory. For example, if you
have a project called "My Project," you would store
everything related to this project in a directory called myproject.
Where the project directory lives is up to you. I generally have all
of my project directories under a src directory. We'll lay
out a simple project called myproject. Listing 3.1 shows how
you might lay this out.
task1
param1="value1" param2="value2"><task2
param3="value3" ></target>
The <target> tag has three attributes: name,
depends, if, unless, descriptiondefault, and basedir.
The
name attribute gives the target a name.
The
depends attribute are a comma-separated list of names of
targets on which this target depends.
The
if attribute the name of the property that must be set
in order for this target to execute.
The
unless attribute the name of the property that must not
be set in order for this target to execute.
The
description attribute a short description of this
target's function.
Targets
must have a name and may have several additional attributes that
determine when and if the target actually gets executed. The target
is made up of one or more Tasks like invoke a command or another
program. Targets can have Dependencies, examples: 'install' depends
on 'compile', Targets can handle cascading dependencies, each
Dependency is handled only once, dependency executed only if
required.
It should be noted, however, that Ant's depends attribute only
specifies the order in which targets should be executed - it does
not affect whether the target that specifies the dependency(s) gets
executed if the dependent target(s) did not (need to) run.
Ant tries to execute the targets in the depends attribute in the
order they appear (from left to right). Keep in mind that it is
possible that a target can get executed earlier when an earlier
target depends on it.A target gets executed only once, even when
more than one target depends on it .
A <task>
is a piece of code that can be executed.
A task can have multiple attributes (or arguments, if you prefer).
The value of an attribute might contain references to a property.
These references will be resolved before the task is executed. Tasks
have a common structure: <name attribute1="value1"
attribute2="value2" ... />
where name is the name of the task, attributeN is the attribute
name, and valueN is the value for this attribute.
Each task element of the buildfile can have an id attribute and can
later be referred to by the value supplied to this. The value has to
be unique. Each Task is bound to a Java class file that Ant
executes, passing to it any arguments or sub-elements defined with
that task. The Ant tool is extensible and it allows you to create
your own tasks
Typical
build.xml Tasks
init, sets properties, prepare, creates directories, build, builds
the system, package, creates jar file, install, installs an
application to Tomcat or other engine, deploy, deploy a WAR engine,
reload, update previously installed application engine, redeploy.
Properties
A project can have a set of properties. These might be set in the
buildfile by the property task, or might be set outside Ant. A
property has a name and a value; the name is case-sensitive.
Properties may be used in the value of task attributes. This is done
by placing the property name between "${" and
"}" in the attribute value. For example, if there is a
"builddir" property with the value "build", then
this could be used in an attribute like this: ${builddir}/classes.
This is resolved at run-time as build/classes.
Built-in Properties
Ant provides access to all system properties as if they had been
defined using a <property> task. For example, ${os.name}
expands to the name of the operating system. For a list of system
properties see the Javadoc of System.getProperties.
In addition, Ant has some built-in properties:
basedir the absolute path of the project's
basedir (as set with the basedir attribute of <project>). ant.file the absolute path of the
buildfile. ant.version the version of Ant ant.project.name the name of the project
that is currently executing; it is set in the name attribute of
<project>. ant.java.version the JVM version Ant
detected; currently it can hold