I'm trying out a tutorial example, and, noted that when running the last line of the batch file, it can't seem to find the toaster

, although when running the command by opening a console window and simply typing the last line it seems to work.
|
Code:
|
run_demo.bat
@echo off
rem demonstrates the use of calling a remote method
rem javac Product*.java
rmic -v1.2 ProductImpl 2> rmic.error.log
start rmiregistry 2>>rmic.error.log
start java ProductServer 2> ProductServer.log //I have to run this manually; otherwise an err is displayed (see error).
java ProductClient
pause
Product.java
import java.rmi.*;
/**
The interface for remote product objects.
*/
public interface Product extends Remote
{
/**
Gets the description of this product.
@return the product description
*/
String getDescription() throws RemoteException;
}
ProductClient.java
import java.rmi.*;
import java.rmi.server.*;
import javax.naming.*;
/**
This program demonstrates how to call a remote method
on two objects that are located through the naming service.
*/
public class ProductClient
{
public static void main(String[] args)
{
System.setProperty("java.security.policy", "client.policy");
System.setSecurityManager(new RMISecurityManager());
String url = "rmi://localhost/";
/*TODO change to "rmi://yourserver.com/" when server runs on remote machine
yourserver.com*/
try
{
Context namingContext = new InitialContext();
Product c1 = (Product) namingContext.lookup(url + "toaster");
Product c2 = (Product) namingContext.lookup(url + "microwave");
System.out.println(c1.getDescription());
System.out.println(c2.getDescription());
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
ProductImpl.java
import java.rmi.*;
import java.rmi.server.*;
/**
This is the implementation class for the remote product
objects.
*/
public class ProductImpl
extends UnicastRemoteObject
implements Product
{
/**
Constructs a product implementation
@param n the product name
*/
public ProductImpl(String n) throws RemoteException
{
name = n;
}
public String getDescription() throws RemoteException
{
return "I am a " + name + ". Buy me!";
}
private String name;
}
ProductServer.java
import java.rmi.*;
import java.rmi.server.*;
import javax.naming.*;
/**
This server program instantiates two remote objects,
registers them with the naming service, and waits for
clients to invoke methods on the remote objects.
*/
public class ProductServer
{
public static void main(String args[])
{
try
{
System.out.println("Constructing server implementations...");
ProductImpl p1 = new ProductImpl("Blackwell Toaster");
ProductImpl p2 = new ProductImpl("ZapXpress Microwave Oven");
System.out.println("Binding server implementations to registry...");
Context namingContext = new InitialContext();
namingContext.bind("rmi:toaster", p1);
namingContext.bind("rmi:microwave", p2);
System.out.println("Waiting for invocations from clients...");
}
catch (Exception e)
{
e.printStackTrace();
}
}} |
|
Code:
|
Error
Displayed when running run_demo.bat
javax.naming.NameNotFoundException: toaster
at com.sun.jndi.rmi.registry.RegistryContext.lookup(Unknown Source)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at ProductClient.main(ProductClient.java:35)
Press any key to continue . . . |
Environment notes:
Microsoft Windows [Version 6.0.6001] //Windows Server 2008 x64
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>java -version
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)
C:\Users\Administrator>