SunQuest
 
       Java
  Home arrow Java arrow Page 2 - Deploying Java Applets
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Deploying Java Applets
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2008-04-17

    Table of Contents:
  • Deploying Java Applets
  • Deploying as an Executable JAR
  • Deploying with Java Web Start
  • Accessing the Default Browser
  • Dynamic Linking Using Reflection

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Deploying Java Applets - Deploying as an Executable JAR


    (Page 2 of 5 )

    Besides applet distribution, you can also use JAR files as self-contained executables. The user simply copies the JAR file to the desktop or a directory on the hard drive and it is ready to run. If the executable is a Swing application, the user double-clicks the JAR and it launches the program in a new window. If the executable is a command-line application, the user enters thejavacommand with the-jaroption.

    java -jar fraction.jar
    java -cp J:\lib com.croftsoft.apps.fraction.FractionAction

    Double-clicking or using the command-line-jaroption to launch the game is much easier on the player than specifying theclasspathand class name with the full package-name prefix on the command line. Contrast the two precedingjavacommands, one that uses the
    -jaroption and the other that does not.

      public static void main ( String [ ] args )

    When players launch an executable JAR file, thejavacommand framework looks for a staticmain()method within a designated class and calls it. This causes your game to start running. In this sense themain()method can be considered a lifecycle method. I realize that I am stretching this a bit.

    Making the Manifest

    A JAR file often contains many classes, and more than one of these classes could have amain()method. To distinguish which class should have itsmain()method launched, thejavacommand looks for aMain-Classentry in the manifest file.

    Main-Class: com.croftsoft.apps.fraction.FractionAction

    The preceding code is a line in a manifest file, possibly the only line. It is written in the standard name-value pair format commonly used in property files before XML came about. You separate the class name value from the property name by a colon and a space. 


    CAUTION  Keep in mind that only one space can follow the colon. If you put two spaces before the class name, it simply does not work.


    jar -cvfm collection.jar manifest.txt .

    Your JAR file normally includes a blank manifest file automatically asMETA-INF/MANIFEST.MFwhen you use thejarcommand. To include a non-empty manifest file that contains yourMain-Classentry, you need to use the-moption to thejarcommand. In the above example, thejarcommand is instructed to include the text filemanifest.txt. Whenmanifest.txtis included, it is automatically namedMANIFEST.MFand stored in theMETA-INFdirectory within the archive.

      <jar
        jarfile="collection.jar"
        basedir="jar"
        manifest="bld/apps/collection/ manifest.txt"/>

    In an Ant build file, you use themanifestattribute to specify the path to the manifest file to include.

    Securing the Insecure

    Executable JAR files generally run on the client platform with unrestricted access to sensitive resources such as the hard drive and Internet connections by default. This can make some knowledgeable users leery of playing games distributed as executable JARs, especially when they do not know the distributor well. Such users would generally prefer to play games that are automatically restricted to a security sandbox such as those distributed as a browser applet or as a Java Web Start application.

    java -Djava.security.manager -jar collection.jar

    You can specify the security manager to use when you run JAR files using thejavacommand propertyjava.security.manager. In the preceding command-line example, no value for this property is given so the restrictions that would be imposed upon an unsigned applet running in a browser are enforced upon the executable JAR. If you use this property, you should be safe. Keep in mind that the game might throw someSecurityExceptions and fail to run properly if it was not designed to run within a security sandbox.

    More Java Articles
    More By Apress Publishing


       · This article is an excerpt from the book "Advanced Java Game Programming," published...
     

    Buy this book now. This article is excerpted from chapter two of Advanced Java Game Programming, written by David Wallace Croft (Apress; ISBN: 1590591232). Check it out today at your favorite bookstore. Buy this book now.

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...

    Iron Speed

    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway