Java - make a jar file and include external classes or jar files, creating keystore, and signing a jar app

Compiling java app


D:\java_apps\myapp>javac -verbose -sourcepath src_code_dir -classpath extlib\jai-1_1_4-pre-dr-b03-lib-windows-i586-28_Sep_2009\lib\ext\jai_codec.jar;"C:\Program Files\Java\jre6\lib\plugin.jar"; -d sod sod\org\myapp\ScanDriverApplet.java

-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


D:\java_apps\myapp>keytool -keystore mykeystorefilename -genkey -alias myappalias

-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


D:\java_apps\my_app>jar -cvfe ../myapp.jar -C org


-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 myappalias
Results 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

Popular posts from this blog

LVM: How to remove a volume using pvremove

Using Oracle 11g thru VirtualBox appliance in Mac OS X Lion

Use Shell Editor for Eclipse for editing bash, ksh, csh in Unix/Linux system