帮忙看看我得ejb客户端

TopCool
03-06-09 1 118

报错
D:\Temp\jboss\testejb>java InterestClient
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
aces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: o
rg.jnp.interfaces.NamingContextFactory]

下面是源代码:
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.util.*;
import javax.naming.*;

import org.jboss.docs.interest.Interest;
import org.jboss.docs.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
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL,"jnp://localhost:1099");
//properties.put(Context.PROVIDER_URL_PKGS,"org.jboss.naming:org.jnp.interfaces");

InitialContext jndiContext = new InitialContext(properties);
System.out.println("Got context");

// Get a reference to the Interest Bean
Object ref = jndiContext.lookup("java:comp/env/ejb/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());
}
}
}
哪位大哥帮忙一下,ejb部署上去了,然后写一个客户端,调试。
结果就不知道怎么错了。

TopCool
2003-06-10 14:28

banq帮我看看呀,
有人说我得xml里的jndi名字写错了,也有的说我的classpath忘了家jbossall-client.jar

可是都不行,不知道为什么,请教~~