• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Problems and Problems

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ranchers,
I'm trying to execute this code below in Eclipse 3.4.1 + Jboss 5.0 but problems heppes.

I have this simple code:

My Bean...

package test;

import javax.ejb.Stateless;

/**
* Session Bean implementation class StatelessCalculator
*/
@Stateless
public class StatelessCalculator implements StatelessCalculatorLocal {

/**
* Default constructor.
*/
public StatelessCalculator() {
// TODO Auto-generated constructor stub
}

public double add(double a, double b)
{
return a + b;
}


}



My Remote...


package test;
import javax.ejb.Remote;

@Remote
public interface StatelessCalculatorLocal {
public double add(double a, double b);
}



My simple Client...

package test;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

public class ClientCalc {

/**
* @param args
*/
public static void main(String[] args) {
System.out.println("test");
try {
Context jndiContext = new InitialContext();
Object ref = jndiContext.lookup("StatelessCalculator");
StatelessCalculatorLocal calc = (StatelessCalculatorLocal) PortableRemoteObject.narrow(ref, StatelessCalculatorLocal.class);
System.out.println("4 + 3 = " + calc.add(4, 3));
}
catch (NamingException ne) {
ne.printStackTrace();
}

}

}



And when execute the client like Java Application I have it:

test
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at test.ClientCalc.main(ClientCalc.java:20)



Thank youuu,
Higor
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Higor, please use a meaningful subject line. You can change the subject line by clicking the edit button.

As far as the error goes, did you provide a jndi.properties file?

Also, with EJB3 there is no need to use PortableRemoteObject.narrow().
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am also not positive, but can you return a primitive from an EJB call? I thought they needed to be objects. But I can be totally wrong, here, I am just used to always returning either an Object or null.

Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic