Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compilation Problems with EJBHome in Client.

 
Unnsse Khan
Ranch Hand
Posts: 511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am using the J2EE 1.3 Reference Implementation and here are the files I created:

===========================================================================

The Client:

package umk.bank.interest;

import java.rmi.*;
import javax.rmi.*;
import javax.ejb.*;
import javax.naming.*;

/**
* Test Client for 'Interest' EJB.
*/

public class TestClient {
public static void main (String args []) throws Exception {
Interest interest = getInterest();
double principal = 10000.00;
double rate = 10.00;
int terms = 10;
System.out.println("Principal = $" + principal);
System.out.println("Rate(%) = " + rate);
System.out.println("Terms = " + terms);
System.out.println("Interest = $" +
interest.getInterestOnPrincipal(principal, rate, terms));
System.out.println("Total = $" + interest.getTotalRepayment (principal, rate, terms));
interest.remove();
}

===========================================================================

/**
* Get an instance of the Interest EJB.
*/
public static Interest getInterest() throws
CreateException, RemoteException, NamingException {
InitialContext initialContext = new InitialContext();
Object o = initialContext.lookup("Interest");
InterestHome = (InterestHome)
PortableRemoteObject.narrow(o, InterestHome.class);
return home.create();
}
}
===========================================================================
The EJBHome interface:

package umk.bank.interest;

import java.rmi.*;
import javax.ejb.*;

/**
* Remote home interface (factory interface) for Interest EJB.
*/

public interface InterestHome extends EJBHome {
/**
* Factory method for creating an instance of the EJB.
*/
public Interest create () throws CreateException, RemoteException;
}

===========================================================================
The EJBLocal interface:

package umk.bank.interest;

import java.rmi.*;
import javax.ejb.*;

/**
* Local interface for business methods
* that use the 'Interest EJB'
*/

public interface InterestLocal extends EJBLocalObject {
/**
* Calculate the interest payable on a certain principal,
* at a specified interest rate per term, for a specific
* number of terms.
*/

public double getInterestOnPrincipal(double principal, double interestPerTerm, int terms);

/**
* Calculate the total amount payable on a certain principal,
* at a specified interest rate per term, for a specific number
* of terms.
*/

public double getTotalyRepayment (double principal, double interestPerTerm, int terms);
}

===========================================================================

EJB Local Home Interface:

package umk.bank.interest;

import java.rmi.*;
import javax.ejb.*;

/**
* Local home interface for 'Interest' EJB.
*
* Used for EJB that reside in the same server (JVM).
*/

public interface InterestLocalHome extends EJBLocalHome {

/**
* Factory method that creates a local instance
* of the 'Interest' EJB.
*/

public InterestLocalHome create() throws CreateException;
}

===========================================================================

The Remote Interface:

package umk.bank.interest;

import java.rmi.*;
import javax.ejb.*;

/**
* Remote interface for distributed access.
*
* This interface defines the business methods used
* by the Interest EJB.
*/

public interface Interest extends EJBObject {

/**
* Calculate the interest payable on a certain
* principal, at a specified (percent) interest
* rate per term, for a specific number of terms.
*/

public double getInterestOnPrincipal(double principal, double interestPerTerm, int terms) throws RemoteException;

/**
* Calculate the total amount payable on a certain
* principal, at a specified (percent) interest rate
* per term, for a specific number of terms.
*/

public double getTotalyRepayment(double principal, double interestPerTerm, int terms)throws RemoteException;
}

===========================================================================

Actual bean implementation:

package umk.bank.interest;

import javax.ejb.*;

/**
* Actual implementation for the 'Interest' EJB.
*/

public class InterestBean implements SessionBean {

/**
* Keep a reference to the session context object.
*/

protected SessionContext sessionContext;

/**
* Calculate the interest payable on a certain
* principal, at a specified (percent) interest
* rate per term, for a specific number of terms.
*/

public double getInterestOnPrincipal(double principal, double interestPerTerm, int terms) {
log ("Called getInterestOnPrincipal");
return principal * Math.pow((1 + interestPerTerm / 100.0), terms) - principal;
}

/**
* Calculate the total amount payable on a certain
* principal, at a specified (percent) interest rate
* per term, for a specific number of terms.
*/

public double getTotalyRepayment(double principal, double interestPerTerm, int terms) {
log ("Called getTotalRepayment");
return principal * Math.pow ((1 + interestPerTerm / 100.0), terms);
}

/**
* Set sessionContext is called by the container
* on initialization; conventionally we store
* the passed reference to a SessionContext object.
*/
public void setSessionContext(SessionContext object) {
this.sessionContext = sessionContext;
log("Called setSessionContext");
}

/**
* ejbCreate is called on initialization.
*/
public void ejbCreate() {
log ("Called ejbCreate");
}

/**
* ejbRemove may be called when the container tidies
* up the EJB instance pool (stateless session), or when
* the client class remove(stateful session).
*/
public void ejbRemove() {
log("Called ejbRemove");
}

/**
* ejbActivate is associated with memory management in
* stateful session EJBs; in stateless session EJBs,
* it is never called / invoked.
*/
public void ejbActivate() {
log("Called ejbActivate");
}

/**
* ejbPassivate, same commentary as with ejbActivate.
*/
public void ejbPassivate() {
log("Called ejbPassivate");
}

/**
* Dump a message to a standard out, and thereby
* to the server's log mechanism.
*/
public void log(String s) {
System.out.print("Interest: ");
System.out.println(s);
}
}

===========================================================================

All of these are in the a directory called F:\DevProjects\Java Projects\J2EE Projects\Bank\src

I have another directory that is in the same level as 'src' called 'dist',

When I compiled everything by using:

F:\DevProjects\Java Projects\J2EE Projects\Bank\src\javac -d ..\dist *.java

Everything compiled except for the TestClient class, here were the errors:

F:\DevProjects\Java Projects\J2EE Projects\Bank\src>javac -d ..\dist *.java
TestClient.java:23: cannot resolve symbol
symbol : method getTotalRepayment (double,double,int)
location: interface umk.bank.interest.Interest
System.out.println("Total = $" + interest.getTot
alRepayment(principal, rate, terms));
^
TestClient.java:34: cannot resolve symbol
symbol : variable InterestHome
location: class umk.bank.interest.TestClient
InterestHome = (InterestHome)
^
TestClient.java:36: cannot resolve symbol
symbol : variable home
location: class umk.bank.interest.TestClient
return home.create();
^
3 errors

===========================================================================

When I tried to append the my CLASSPATH, I got 6 errors instead of 3:

F:\DevProjects\Java Projects\J2EE Projects\Bank\src>javac -d ..\dist -classpath
%CLASSPATH%;dist TestClient.java
TestClient.java:30: cannot resolve symbol
symbol : class Interest
location: class umk.bank.interest.TestClient
public static Interest getInterest() throws
^
TestClient.java:14: cannot resolve symbol
symbol : class Interest
location: class umk.bank.interest.TestClient
Interest interest = getInterest();
^
TestClient.java:34: cannot resolve symbol
symbol : variable InterestHome
location: class umk.bank.interest.TestClient
InterestHome = (InterestHome)
^
TestClient.java:34: cannot resolve symbol
symbol : class InterestHome
location: class umk.bank.interest.TestClient
InterestHome = (InterestHome)
^
TestClient.java:35: cannot resolve symbol
symbol : class InterestHome
location: class umk.bank.interest.TestClient
PortableRemoteOb
ject.narrow(o, InterestHome.class);

^
TestClient.java:36: cannot resolve symbol
symbol : variable home
location: class umk.bank.interest.TestClient
return home.create();
^
6 errors

===========================================================================
My CLASSPATH is:

F:\DevProjects\Java Projects\J2EE Projects\Bank\src>echo %CLASSPATH%
.;F:\DevTools\Java\JMF21~1.1E\lib\sound.jar;F:\DevTools\Java\JMF21~1.1E\lib\jmf.
jar;F:\DevTools\Java\JMF21~1.1E\lib;.;F:\DevTools\Java\j2sdk1.4.2_04\lib\tools.j
ar;F:\DevTools\Java\j2sdk1.4.2_04\jre\lib\rt.jar;F:\DevTools\Java\Tomcat\jakarta
-tomcat-5.0.19\common\lib\servlet-api.jar;F:\DevTools\Java\Tomcat\jakarta-tomcat
-5.0.19\common\lib\jsp-api.jar;F:\DevTools\Java\j2sdkee1.3.1\lib\j2ee.jar

===========================================================================

I am using the J2EE Reference Implementation 1.3 on WinXP.

Can anyone help?
--------------------

Unnsse M. Khan
Sun Certified Programmer for the Java 2 Platform 1.4
 
Mishra Anshu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to compile all the files except the client one.
Although I haven't gone through your codes. I hope it must be error free.

After you have compiled your bean(Home, remote, bean class), then deploy it using the deploytool available with the J2ee RI.
While deploying, the wizard will ask you, if you need a jar file to be returned for you client application. You have to just check the checkbox.

Now when the application is deployed on the server, you should run your clent application keeping that returned jar in the classpath.

This jar actually cotains the stub implementation of the remote object.
Hope it will help.
 
Vitaliy Geraymovych
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't compile you code but I see that you are calling getTotalRepayment but defined getTotalyRepayment.

Vitaliy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic