Differences
This shows you the differences between two versions of the page.
— |
help:sysnews:acm_jar_applets [2010/11/24 18:10] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Using acm.jar ====== | ||
+ | |||
+ | The ACM Java Task Force ([[http:// | ||
+ | |||
+ | Programs using acm.jar may be compiled and executed from the command line, or within your favorite Java IDE (e.g., Netbeans, DrJava). It is also possible to run your JTF programs as an applet within a browser or via the appletviewer. | ||
+ | |||
+ | While the IDEs have their own way of incorporating the acm.jar file, if you want it included at those times you are compiling or running java at the command line you have three options: | ||
+ | |||
+ | |||
+ | =====-. manually add acm.jar each time ===== | ||
+ | |||
+ | You can add ``-classpath .:/ | ||
+ | javac -classpath .:/ | ||
+ | |||
+ | =====-. change your environment for the current session ===== | ||
+ | |||
+ | You can add acm.jar to your classpath in your current bash shell (your terminal session) with the following command: | ||
+ | |||
+ | test -z $CLASSPATH && export CLASSPATH=.:/ | ||
+ | |||
+ | If you enter (or cut and paste) the above command in your terminal it will create a classpath for you if you don't have one, or it will add acm.jar to your existing classpath if you already have one. | ||
+ | |||
+ | =====-. Change your environment for all sessions ===== | ||
+ | |||
+ | If you are going to be using acm.jar regularly, the easiest thing to do in the long run is to set your classpath in your .bashrc file. ((You didn't change your shell did you? Everyone here defaults to bash, if you changed it, then hopefully you know how to set variables in your new shell. | ||
+ | |||
+ | To make this modification, | ||
+ | # | ||
+ | # Added to include current directory and acm.jar to the CLASSPATH | ||
+ | # | ||
+ | if [ -z " | ||
+ | export CLASSPATH=.:/ | ||
+ | else | ||
+ | export CLASSPATH=$CLASSPATH.:/ | ||
+ | fi | ||
+ | |||
+ | The lines above do the exact same thing as the ``test -z`` line in the previous section does, but they do it less opaquely and so are a better choice for your .bashrc file. Once you add these lines and save your .bashrc file, and time((I hope someone is saying "But Greg, the .bashrc file is not always read, there are some circumstances where the .bash_login will be read instead!" | ||
+ | |||
+ | |||
+ | ===== Out of date information ===== | ||
+ | The information that follows is largely obsolete, it is left here for reference purposes only | ||
+ | |||
+ | Here are Linux/Mac command line instructions for preparing your JTF programs to run as an applet: | ||
+ | |||
+ | * Compile your program with acm.jar on the class path: | ||
+ | | ||
+ | (this creates the file MyApplet.class) | ||
+ | * Create a copy of the acm.jar file: | ||
+ | ``cp acm.jar MyApplet.jar`` | ||
+ | * Add your compiled class file(s) to your new jar file: | ||
+ | ``jar uf MyApplet.jar MyApplet.class`` | ||
+ | * Create an HTML file containing the applet tag for your program. For example, here is MyApplet.html: | ||
+ | |||
+ | < | ||
+ | <applet archive=MyApplet.jar | ||
+ | code=MyApplet.class | ||
+ | width=500 height=300> | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | * Run your applet, either by opening MyApplet.html in your favorite browser, or via the appletviewer: | ||
+ | | ||