Deployment

ITP HELP | RecentChanges | Preferences

APPLET AND AN APPLICATION

Especially during development, it is nice to have the same code work as both an applet and an application. Basically you make your project as an JApplet (instead of JFrame). When it needs to run as an Applet, things are easy, you put your initialization code in init and start methods (the start up methods for an Applet) and you are on your way. When the program needs to run as an application, your main method (the start up method for applications) creates a JFrame to which the applet is added. It is as if you are creating a window to serve as the browser for your JApplet. The main method must also take responsibility for calling the init and start methods that the Browser ordinarily would. This main method is ignored when the code is run as an applet.

public class Thing extends JApplet  {

	boolean isStandalone = false;
        String[] args; //this is how parameters come in for an applicaton

	public void start() {
	       if (isStandalone == false) {//parameters come in differently on applets and applications
		    bla =  getParameter("myParam");  			
                } else {
	            bla  = args[0];
		}
		
	}
	// Initialize the applet
	public void init() {
	}
	
	// Standard method to stop the applet
	public void stop() {
	
	}
	// Standard method to destroy the applet
	public void destroy() {}

	// Main entry point when running standalone
	public static void main(String[] _args) {
		Thing applet = new Thing();
		applet.isStandalone = true;
		frame = new JFrame();
                frame.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        applet.stop();
                        applet.destroy();
                    }
                });
                frame.setTitle(applet.getClass().getName());
                frame.getContentPane().add(applet, BorderLayout.CENTER);
                frame.setSize(width, height);
                frame.setUndecorated(true);
                frame.setBackground(Color.black);
                frame.setVisible(true);		
                args = _args;
                applet.init();  //this frame is acting as the browser and must start the applet
		applet.start();
		frame.pack();
	}

}

JAR FILES

You can combine all of your java .class files into a single file called a .jar file. Java comes with a utility for doing this on the command line, or more conveniently you might use the export options in Eclipse. You can also include a manifest file within the jar [more] which acts as a packing slip describing the contents of the package. Most importantly the manifest can specify the class with the "main" method that you want called first. If you specify this, when you double click on the jar file it may (depending on how the .jar extention is mapped on your machine) run your application. When you export from Eclipse don't press "Finish" too soon and forget to go to the very last screen in the wizard for specifying the main class.

You can always run a jar file using a command line.

cd mydirectory
java -jar yourJarFile.jar
On a pc you can then put these two lines in a text file with a .bat extension and your app would launch by double clicking on that file (is there a mac equivalent?).

Of course this is very optimistic because it assumes that the whereabouts of all the files you are using for non standard java stuff (eg vxp.jar comm.jar QTJava.zip) are known (are in the classpath) by your current Java Virtual Machine. To ensure this you can use the -classpath option to specify the other files that you need. Theoretically the same folder as your jar will will automatically be in the classpath but you may even have to specify that with a period "." meaning this directory. You can give a list of several directories, I think they must be separated by semicolons on the PC and colons on the Mac.

java -classpath peer.jar:vxp.jar PeerStreamVideoApp //includes two supporting files, peer.jar and vxp.jar that are in the same directory that the command prompt is pointing at on a mac.

Even if the class with the main method is not listed in the manifest or if you want to use the same jar file to run different apps, you can put the jar in the classpath specify with class for java to call first.

You can also run the jar file in an applet:

<APPLET CODE = "NameOFClassWithMain.class" ARCHIVE = "yourJarFile.jar" WIDTH = "600" HEIGHT = "125" NAME = "MyApplet">
</APPLET>

SIGNING

Running your code in a browser will likely run into security problems. Among the things that we do that are not allowed within a browsers "sandbox" are reading and writing files, connecting to machines that we did not get served from, and accessing video hardware. The standard way to get around this is to sign your applet so people can make an informed decision about trusting you. It is somewhat expensive to get a proper certificate from a trusted sources (Thawte $200 Verisign $400) but you can fake it with a self signed certificate,[1][2]

CVS

CVS is a great way to work with other people on the same code or just to keep your project organized for yourself on different machines. It is is installed on stage and integrates well into Eclipse.

CVS repository

  1. For NetEx you can use an existing CVS repository at /home/dano/CVS/NetExClass/. You can skip to the next step of just associating your project with it.
  2. Create a folder on stage to hold your CVS stuff, maybe above your public_html folder so it is not accessable, let's say /home/netid/myCVS/myProjectName/.
  3. You can make it a CVS repository with this simple command. "cvs -d /home/netid/myCVS/myProjectName/ init"

To Associate you Eclipse Project with the CVS repository

  1. Under "Team" menu item in Eclipse, say share project, filling out the server information about where you are going to save it to (specify ssh).
  2. Before you start coding, get the latest files by saying "update"
  3. After you finish working "commit" put your changes back on the server.

To Create an Eclipse Project from a CVS repository

  1. Create project as normal but instead of "Java Project" specify "CVS"

ITP HELP | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited March 30, 2005 12:43 pm (diff)
Search:
To EDIT, You have to enter an ADMINISTRATOR password (guess) in Preferences. And refresh