Problem compiling Test Client
javauser Feb 26, 2002 9:13 PMI am having trouble compiling the Test Client
javac -classpath /usr/lib/jboss/lib/ext/ejb.jar com/web_tomorrow/interest/InterestClient.java
import org.interest.InterestHome;
^
org\interest\InterestClient.java:35: cannot resolve symbol
symbol : class InterestHome
location: class org.interest.InterestClient
InterestHome home = (InterestHome)
^
org\interest\InterestClient.java:35: cannot resolve symbol
symbol : class InterestHome
location: class org.interest.InterestClient
InterestHome home = (InterestHome)
^
org\interest\InterestClient.java:36: cannot resolve symbol
symbol : class InterestHome
location: class org.interest.InterestClient
PortableRemoteObject.narrow(ref, InterestHome.class);
^
org\interest\InterestClient.java:39: cannot resolve symbol
symbol : class Interest
location: class org.interest.InterestClient
Interest interest = home.create();
^
6 errors
I donot have a problem when I run the following commands
1. javac -classpath /usr/lib/jboss/lib/ext/ejb.jar com/web_tomorrow/interest/Interest.java
2. javac -classpath /usr/lib/jboss/lib/ext/ejb.jar com/web_tomorrow/interest/InterestHome.java
3. javac -classpath /usr/lib/jboss/lib/ext/ejb.jar com/web_tomorrow/interest/InterestBean.java
4. jar cvf interest.jar com/web_tomorrow/interest/Interest.class \
com/web_tomorrow/interest/InterestHome.class \
com/web_tomorrow/interest/InterestBean.class \
META-INF
However when I try and compile the client I am having problems - Cannot resolve symbol
the files are as follows
InterestClient.java
package org.interest;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import org.interest.Interest;
import org.interest.InterestHome;
/** This simple application tests the 'Interest' Enterprise JavaBean which is
implemented in the package 'org.jboss.docs.interest'. For this to work, the
Bean must be deployed on an EJB server.
*/
class InterestClient
{
/** This method does all the work. It creates an instance of the Interest EJB on
the EJB server, and calls its `calculateCompoundInterest()' method, then prints
the result of the calculation.
*/
public static void main(String[] args)
{
// Enclosing the whole process in a single `try' block is not an ideal way
// to do exception handling, but I don't want to clutter the program up
// with catch blocks
try
{
// Get a naming context
InitialContext jndiContext = new InitialContext();
System.out.println("Got context");
// Get a reference to the Interest Bean
Object ref = jndiContext.lookup("interest/Interest");
System.out.println("Got reference");
// Get a reference from this to the Bean's Home interface
InterestHome home = (InterestHome)
PortableRemoteObject.narrow(ref, InterestHome.class);
// Create an Interest object from the Home interface
Interest interest = home.create();
// call the calculateCompoundInterest() method to do the calculation
System.out.println("Interest on 1000 units, at 10% per period, compounded over 2 periods is:");
System.out.println(interest.calculateCompoundInterest(1000, 0.10, 2));
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
Interest.java
package org.interest;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
/**
This interface defines the `Remote' interface for the `Interest' EJB. Its
single method is the only method exposed to the outside world. The class
InterestBean implements the method.
*/
public interface Interest extends EJBObject
{
/**
Calulates the compound interest on the sum `principle', with interest rate per
period `rate' over `periods' time periods. This method also prints a message to
standard output; this is picked up by the EJB server and logged. In this way we
can demonstrate that the method is actually being executed on the server,
rather than the client.
*/
public double calculateCompoundInterest(double principle,
double rate, double periods) throws RemoteException;
}
InterestBean.java
package org.interest;
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
/**
This class contains the implementation for the 'calculateCompoundInterest'
method exposed by this Bean. It includes empty method bodies for the methods
prescribe by the SessionBean interface; these don't need to do anything in this
simple example.
*/
public class InterestBean implements SessionBean
{
/**
Calulates the compound interest on the sum `principle', with interest rate per
period `rate' over `periods' time periods. This method also prints a message to
standard output; this is picked up by the EJB server and logged. In this way we
can demonstrate that the method is actually being executed on the server,
rather than the client.
*/
public double calculateCompoundInterest(double principle,
double rate, double periods)
{
System.out.println("Someone called `calculateCompoundInterest!'");
return principle * Math.pow(1+rate, periods) - principle;
}
/** Empty method body
*/
public void ejbCreate()
{}
/** Every ejbCreate() method ALWAYS needs a corresponding
ejbPostCreate() method with exactly the same parameter types.
*/
public void ejbPostCreate()
{}
/** Empty method body
*/
public void ejbRemove()
{}
/** Empty method body
*/
public void ejbActivate()
{}
/** Empty method body
*/
public void ejbPassivate()
{}
/** Empty method body
*/
public void setSessionContext(SessionContext sc)
{}
}
InterestHome.java
package org.interest;
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
/**
This interface defines the 'home' interface for the 'Interest' EJB.
*/
public interface InterestHome extends EJBHome
{
/**
Creates an instance of the `InterestBean' class on the server, and returns a
remote reference to an Interest interface on the client.
*/
Interest create() throws RemoteException, CreateException;
}
Your help is much appreciated.