| Home: www.vipan.com | Vipan Singla | e-mail: vipan@vipan.com |
//Display system environment as Java sees it
public class JavaEnv
{
private static JavaEnv shark;
public static void main(String args[]){shark = new JavaEnv(); shark.init();}
public void init()
{
java.util.Properties prop = System.getProperties();
java.util.Enumeration enum = prop.propertyNames();
System.out.println(
"***System Environment As Seen By Java********************");
System.out.println(
"***Format: PROPERTY = VALUE******************************");
for (; enum.hasMoreElements() ;)
{
String key = (String)enum.nextElement();
System.out.println(key + " = " + System.getProperty(key));
}
}
}
|
javac com/abc/project1/Foo.java
- Use "\" in Windows
javac com\abc\project1\Foo.java
-classpath) (default is the current working directory)javac -classpath /junk/someDir com/abc/project1/Foo.java
- Multiple paths
javac -classpath /junk/someDir:/junk/someOtherDir com/abc/project1/Foo.java- Use "\" and ";" in Windows
javac -classpath \junk\someDir;\junk\someOtherDir com/abc/project1/Foo.java- .class files embedded in .jar files
javac -classpath /junk/someDir:/anywhere/myJar.jar:/elsewhere/yourJar.jar com/abc/project1/Foo.java
javac -d /junk/someDir -classpath /junk/someDir com/abc/project1/Foo.java
javac -d /junk/someDir -classpath /junk/someDir -sourcepath /junk com/abc/project1/Foo.java
/usr/java1.2.2/jre or /usr/java1.1
System.out.println( "Bootstrap files are in "
+ System.getProperty("sun.boot.class.path") );
System.out.println( "Extension packages or optional files are in "
+ System.getProperty("java.ext.dirs") );
System.out.println( "User or application specific files are in "
+ System.getProperty("java.class.path") );
|
java Foojava -classpath .:/junk/SomeDir Foojava -cp .:/junk/SomeDir Foojava -classpath /junk/SomeDir Foo myOption1 myOption2java -classpath /junk/SomeDir com.abc.project1.Foojava -classpath /junk/SomeDir -Duser.dir=/junk/someOtherDir com.abc.project1.Foojava -verbose -classpath /junk/SomeDir com.abc.project1.FooMain-Class: Foo
Then, anybody can run the program with the following command
java -jar myProgram.jarjava -jar myProgram.jar myOption1 myOption2- In Windows, just double-click the .jar file. The application will run in the background. No MSDOS console will appear to show output or get input. Only if it is a Java Swing application, the swing window will appear as normal.
- In unix, set the execute permission on myProgram.jar with
chmod 755 program.jar. Then, anybody should be able to run the program by simply issuing the command:
myProgram.jar
myProgram.jar myOption1 myOption2
|
jar cvf /junk/lib/myProgram.jar . jar uvf myMore.jar Foo19.classClass-Path: myWhatever.jar jars/more.jar
jar uvfm myProgram.jar manifest.textjar cvfm myProgram myManifestFile *.classjar tvf myProgram.jar
jar xvf myProgram.jarjar xvf myProgram.jar Foo.class Foo2.classtar command.
public class Foo extends javax.swing.JApplet{ . . . }
public class Foo extends javax.swing.JApplet
{
private static Foo shark;
public static void main(String args[])
{shark = new Foo(); shark.init(); System.exit(0); }
public void init(){ //Your Applet code here . . . }
}
public void start(){ . . . }
public void stop(){ . . . }
public void destroy(){ . . . }
public URL getCodeBase(){ . . . } // URL source directory for applet
public URL getDocumentBase(){ . . . } // URL source directory for html page
public String[][] getParameterInfo(){ . . . } // If implemented, parameters to be specified when calling this applet
public void showStatus(String message){ . . . } // Writes message to browser's status bar
import java.net.URL;
public class Foo extends javax.swing.JApplet
{
private static Foo shark;
public static void main(String args[])
{ shark = new Foo(); shark.init(); System.exit(0); }
public void init()
{
// These 10 system properties are always allowed to be read by an applet
String[] keys = {"java.version", "java.vendor", "java.vendor.url",
"java.class.version", "os.name", "os.arch",
"os.version", "file.separator", "path.separator",
"line.separator"};
java.util.Arrays.sort(keys);
System.out.println(
"***System Environment As Seen By A Java Applet***********");
System.out.println(
"***Format: PROPERTY = VALUE******************************");
for (int i=0; i<keys.length; i++)
{
String key = (String)keys[i];
System.out.println(key + " = " + System.getProperty(key));
}
System.out.println(
"***End of System Environment As Seen By A Java Applet*****");
try {
showStatus("Where am I");
URL coderoot = getCodeBase();
URL docroot = getDocumentBase();
System.out.println("Code root = " + coderoot
+ "\n\t(Protocol = " + coderoot.getProtocol()
+ ", Host = " + coderoot.getHost()
+ ", Port (-1 if none set) = " + coderoot.getPort()
+ ", File (address part after host name) = "
+ coderoot.getFile()
+ ", Ref (address part after file) = " + coderoot.getRef()
+ ")");
System.out.println("Document root = " + docroot
+ "\n\t(Protocol = " + docroot.getProtocol()
+ ", Host = " + docroot.getHost()
+ ", Port (-1 if none set) = " + docroot.getPort()
+ ", File (address part after host name) = "
+ docroot.getFile()
+ ", Ref (address part after file) = " + docroot.getRef()
+ ")");
} catch (Exception e) {
System.out.println("Doesn't seem to be running as an applet!\n" + e);
}
}
}
<HTML>
<HEAD><TITLE>Applet Example</TITLE></HEAD>
<BODY>
<h1>Applet Example</H1><p>
<!-- Replace "Foo.class", "../classes", "trout", "myOption1", "salmon",
and "myOption2" to reflect your applet's class, codebase,
and runtime options -->
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="300"
height="200"
align="baseline"
codebase=
"http://java.sun.com/products/plugin/1.2/jinstall-12-win32.cab#Version=1,2,0,0"
>
<PARAM NAME="code" VALUE="Foo.class">
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.2">
<PARAM NAME="codebase" VALUE="../classes">
<PARAM NAME="trout" VALUE="myOption1">
<PARAM NAME="salmon" VALUE="myOption2">
<COMMENT>
<EMBED type="application/x-java-applet;version=1.2"
width="300"
height="200"
align="baseline"
code="Foo.class"
codebase="../classes"
pluginspage=
"http://java.sun.com/products/plugin/1.2/plugin-install.html"
trout="myOption1"
salmon="myOption2"
><NOEMBED>
</COMMENT>
The content at this location is a Java applet. It requires at least
Microsoft Internet Explorer ver. 4.0 OR Netscape Navigator ver. 4.0.
In addition, please make sure that your browser is java-enabled!
</NOEMBED></EMBED>
</OBJECT>
</BODY>
</HTML>
Here, "codebase" <PARAM> is optional. It specifies the directory where the browser will go to retrieve the applet class file as well as any additional class files that may be referenced by the applet class file. The directory should be in the form of a relative URL. When starting with a "/", it is relative to the main world wide web directory of the virtual server. Otherwise, it is relative to the location of the HTML file which contains the applet calling code.Parameter names are not case-sensitive (trout = Trout = tRout = TROUT). Except for code, codebase, type and version, all other parameter names are made available to the applet class file. e.g.String firstOption = getParameter("Trout"); statement in the applet's .java file will store the string "myOption1" in variable firstOption. Make sure that you check for null before using firstOption further along. The .html author may have forgotten to specify the parameter.
So, for stand alone programs, the end user passes the runtime options on the command line after the class file name. The programmer accesses those runtime options via the "args" String array. For applets, the end user (which is the .html writer) passes the runtime options by specifying values of named parameters in the .html file. The programmer accesses those values by the always-available "getParameter" method. The programmer and the .html writer will have agreed in advance on the name of the parameter which is case-insensitive.
appletviewer myApplet.htmlappletviewer file:///D:/junk/SomeHtmlDir/myApplet.htmlappletviewer http://localhost/myApplet.htmlOn MS Windows 95 and later, to be able to see the output from "System.out.println( . . .)" statements in your programs, you should install JDK 1.2.2 and above. JDK 1.2.2 installs a "Java Plug-In Control Panel" program in "Start->Programs" menu or Windows Control Panel folder. You then enable the "Show Java Console" checkbox in the "Java Plug-In Control Panel" application. Then, everytime you access any applet's HTML file through the browser, a separate window pops up which shows the output from the "System.out.println( . . .)" statements. It also shows all other error and exception information if necessary. (Enabling "java console" in Netscape and MSIE does not work as they can only display the output from the included 1.1.x Java program, not from the plugged-in Java program through the use of <EMBED> and <OBJECT> tags.)
javadoc -verbose -private -d /junk/doc -classpath /junk/SomeDir -sourcepath /junk/src com.mypack com.mypack.utiljavadoc -verbose -private -d /junk/doc -classpath /junk/SomeDir -sourcepath /junk/src/com/mypack Foo.java *.javakeytool -genkey -v -alias duke -validity 365keytool -genkey -v -dname "CN=Your Name, OU=Purchasing Dept, O=ABC Corp., L=Los Angeles, S=California, C=US" -alias "mark" -validity 180keytool -genkey -v -dname "cn=Mypeter schuster, o=Sun Microsystems\, Inc., o=sun, c=us" -alias mark keytool -list -v -alias joekeytool -list -rfckeytool -listkeytool -list -vkeytool -export -v -rfc -alias jane -file janecertfile.cer keytool -export -v -alias jane -file janecertfile.cer keytool -certreq -v -alias jane -file MarkJ.csrkeytool -printcert -v -file /tmp/someCertFile keytool -import -alias joe -file jcertfile.cer keytool -import -trustcacerts -alias joe -file VSMarkJ.cerkeytool -keypasswd -v -alias dukekeytool -storepasswd -v keytool -delete -v -alias sMillerkeytool -keyclone -v -alias sMiller -dest sMillerNewkeytool -selfcert -v -alias sMillerNew -dname "cn=Susan Miller, ou=Accounting Department, o=BlueSoft, c=us"keytool -certreq -v -alias sMillerNewkeytool -import -v -alias sMillerNew -trustcacerts -file VSSMillerNew.cerkeytool -delete -v -alias sMillerjarsigner -verbose bundle.jar janejarsigner -verbose -sigfile TrustMe bundle.jar janejarsigner -sigfile TRUSTME bundle.jar janejarsigner -verbose -signedjar sbundle.jar bundle.jar janejarsigner -verbose -keystore C:\working\mystore -signedjar sbundle.jar bundle.jar jane jarsigner -keystore file:C:\working\mystore bundle.jar jane jarsigner -keystore http://java.sun.com/keystore2 bundle.jar jane jarsigner -verify -verbose bundle.jarjarsigner -keystore /working/mystore -verify -verbose -certs myTest.jar