Java - make a jar file and include external classes or jar files, creating keystore, and signing a jar app
Compiling java app
-d destination directory for class files
-verbose includes information about each class loaded and each source
file compiled.
-classpath Set the user class path, overriding the user class path in the
CLASSPATH environment variable. If neither CLASSPATH or
-classpath is specified, the user class path consists
of the current directory. See Setting the Class Path for more
details.
If the -sourcepath option is not specified, the user class path
is searched for source files as well as class files.
Creating a keystore
-keystore The keystore (database file) location. Defaults to the file .keystore in the user's home directory, as determined by the "user.home" system property, whose value is described inKeystore Location.
-genkey Generates a key pair (a public key and associated private key)
-alias alias will be used to
Results to:
Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]: My Sample Inc.
What is the name of your organizational unit?
[Unknown]: My Sample Inc.
What is the name of your organization?
[Unknown]:
What is the name of your City or Locality?
[Unknown]:
What is the name of your State or Province?
[Unknown]:
What is the two-letter country code for this unit?
[Unknown]:
Is CN=My Sample Inc., OU=My Sample Inc., O=Unknown, L=Unknown, ST=Unknown, C
=Unknown correct?
[no]: yes
Enter key password for
(RETURN if same as keystore password):
D:\java_apps\myapp>
Creating a jar file
-C Temporarily changes directories (
cd
dir) during execution of the jar command while processing the following inputfiles argument. Its operation is intended to be similar to the -C option of the UNIX tar utility. For example:jar uf foo.jar -C classes bar.class
would change to the classes directory and add the bar.class from that directory to foo.jar. The following command,jar uf foo.jar -C classes . -C bin xyz.class
would change to the classes directory and add to foo.jar all files within the classes directory (without creating a classes directory in the jar file), then change back to the original directory before changing to the bin directory to add xyz.class to foo.jar. If classes
holds files bar1
and bar2
, then here's what the jar file would contain using jar tf foo.jar
:META-INF/
META-INF/MANIFEST.MF
bar1
bar2
xyz.class
Signing a jar app: This avoid "Unable to create temporary file" and permission issues, while running applet...
D:\java_apps\my_app>jarsigner -keystore mykeystorefilename myapp.jar myappaliasResults to:
Enter Passphrase for keystore:
Warning:
The signer certificate will expire within six months.
The file size of the jar file will be updated.
Comments