Spread the love! TechSpot Tech Gift Shortlist 2017

Compiling of example programme

By nick_brien53
May 31, 2005
  1. Compiling the Example Programs
    In a real-world scenario in which a service like the compute engine is deployed, a developer would likely create a JAR (Java ARchive) file that contains the Compute and Task interfaces for server classes to implement and client program to use. Next, a developer, perhaps the same developer of the interface JAR file, would write an implementation of the Compute interface and deploy that service on a machine available to clients. Developers of client programs can use the Compute and the Task interfaces, contained in the JAR file, and independently develop a task and client program that uses a Compute service.
    In this section you learn how to set up the JAR file, server classes, and client classes. You will see that the client's Pi class will be downloaded to the server at runtime. Also, the ComputeEngine's remote stub will be downloaded from the server to the client at runtime.

    Build a JAR File of Interface Classes
    First, you need to compile the interface source files in the compute package and then build a JAR file that contains their class files. Let's suppose a user, waldo, has written these particular interfaces and has placed the source files in c:\home\waldo\src\compute (on UNIX:/home/waldo/src/compute). Given these paths, you can use the following commands to compile the interfaces and create the JAR file.


    Microsoft Windows:
    cd c:\home\waldo\src
    javac compute\Compute.java
    javac compute\Task.java
    jar cvf compute.jar compute\*.class

    cd /home/waldo/src
    javac compute/Compute.java
    javac compute/Task.java
    jar cvf compute.jar compute/*.class


    The jar command displays the following output (due to the -v option):

    added manifest
    adding: compute/Compute.class (in=281) (out=196)
    (deflated 30%)
    adding: compute/Task.class (in=200) (out=164)
    (deflated 18%)

    Now you can distribute the compute.jar file to developers of server and client applications so that they can make use of the interfaces.

    When you build either server- or client-side classes with the javac and rmic compilers, you generally need to specify where the resulting class files should reside so that they are network accessible. In this example this location is, for UNIX, /home/user/public_html/classes, because some web servers allow accessing a user's public_html directory via an HTTP URL constructed as http://host/~user/. If your web server does not support this convention, you could use a file URL instead. The file URLs take the form file:/home/user/public_html/classes/ on UNIX or, on the Microsoft Windows platform, file:/c:/home/user/public_html/classes/. You may also select another type of URL, as appropriate.

    The network accessibility of the class files allows the RMI runtime to download code when needed. Rather than defining its own protocol for code downloading, RMI uses URL protocols supported by the Java platform (for example, HTTP) to download code. Note that a full, heavyweight web server is not needed to accomplish this downloading of class files. In fact, a simple HTTP server that provides all of the functionality needed to make classes available for downloading in RMI via HTTP can be found at ftp://ftp.javasoft.com/pub/jdk1.1/rmi/class-server.zip.
  2. RealBlackStuff

    RealBlackStuff TS Rookie Posts: 6,503

    So what do you expect us to do with this piece of fluff?
Topic Status:
Not open for further replies.

Similar Topics

Add your comment to this article

You need to be a member to leave a comment. Join thousands of tech enthusiasts and participate.
TechSpot Account You may also...