File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JBoss/WildFly and the fly likes Step by steyp JNDI look up with jboss 7.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Step by steyp JNDI look up with jboss 7.1" Watch "Step by steyp JNDI look up with jboss 7.1" New topic

Step by steyp JNDI look up with jboss 7.1

Jhonathan Ibanez

Joined: Dec 17, 2012
Posts: 2

First of all I apologize if this was not the right place to puto this question, I am new to javaranch.
I have eclipse juno and jboss AS 7.1 final running on my machine and configured it through it (eclipse juno). I hava a simple stateless bean and its interface (in fact is exactly the same example from the book Enterprise Java Beans 3.1 6th Edition). Here is the code:

package beans;

public class CalculatorBeanBase implements CalculatorCommonBusiness{

public int add(int[] opers){

int sum = 0;
for(int cpers){
return sum;


package beans;

public interface CalculatorCommonBusiness {

public int add(int[] opers);


package beans;

public interface CalculatorRemoteBusiness extends CalculatorCommonBusiness {}

package beans;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

public class SimpleCalculatorBean extends CalculatorBeanBase {}

I am trying to do the following JUnit testing, unfortunately the example mentions something like "using a standard file that we assume to be presente on the classpath" (here is my first problem, I have no idea what this means, I in fact did some research but I cant quite understand how it works, confuses me, and ultimately cant seem to make it work).

package beans;

import javax.naming.Context; import javax.naming.InitialContext;

import junit.framework.TestCase;

import org.junit.BeforeClass; import org.junit.Test;

public class CalculatorIntegrationTestCase {

private static Context namingContext;

private static SimpleCalculatorBean cal;

private static final String JNDI_NAME_CALC = "java:global/";

public static void obtainProxyReferences() throws Throwable
namingContext = new InitialContext();
cal = (SimpleCalculatorBean)namingContext.lookup(JNDI_NAME_CALC);

private void assertAdditionSucceeds(SimpleCalculatorBean cal){

final int[] oper = {2,3,4};
final int expectedSum = 9;
final int actualSum = cal.add(oper);

TestCase.assertEquals("Assert Failed!!. The actual value is not the expected",expectedSum, actualSum);

public void testAdditionUsingBusinessReference() throws Throwable


I need to know how that jndi. properties file works and how I have to set it up. (I read about this last issue, and I got the folloing .txt file and changed its extension to .jar, I dont know if that was right):




Finally I put that .jar file into the classpath (DonĀ“t know if I did it right: rigth-click on project, build path, libraries, add external jars).

I did all the above stuff but I keep getting the following:

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(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.lookup(Unknown Source) at beans.CalculatorIntegrationTestCase.obtainProxyReferences( at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall( at at org.junit.runners.model.FrameworkMethod.invokeExplosively( at org.junit.internal.runners.statements.RunBefores.evaluate( at at at at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests( at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests( at at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

Of course I published the Project (through eclipse though, project>run>run on server). Help would be appreciated
Jhonathan Ibanez

Joined: Dec 17, 2012
Posts: 2
Any help?, I'd appreciate it.
I agree. Here's the link:
subject: Step by steyp JNDI look up with jboss 7.1
It's not a secret anymore!