• Post Reply Bookmark Topic Watch Topic
  • New Topic

setting up jndi properties in eclipse 3.3.2

mark baum
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm trying to run the exercise 4.1 from "Enterprise JavaBeans 3.0", 5th Edition By Richard Monson-Haefel as described in Chapter 24.
I built the structure precisely as described in the example and it works when I run the the ant task "client.run". But it didn't run when I tried to run the Client class in eclipse.
I assumed from the error message that it didn't find the jndi.properties file in client-config, though I added the dir as a source file in the build path, I checked the class path and the path was there:

<classpathentry kind="src" path="src/main"/>
<classpathentry kind="src" path="client-config"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>

So I replaced

Context context;
context = new InitialContext(properties);
Object ref = context.lookup("TravelAgentBean/remote");


Properties properties = new Properties();
properties.put("java.naming.factory.url.pkgs","=org.jboss.naming rg.jnp.interfaces");

and it runs!

Apparently, the jndi.properties are not found...

I assume that the magic is in the ant file that uses "fork=yes"

<target name="run.client" depends="ejbjar">
<java classname="com.titan.clients.Client" fork="yes" dir=".">
<classpath refid="classpath"/>

How is it possible to add the client-config directory so Eclipse could read it properly?

Thanks for help

Scott Selikoff
Posts: 4033
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class-path in a J2EE environment is complicated, far more than in a stand alone environment. Could you copy and paste the exact error message?
mark baum
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Scott,

The error message was

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 com.titan.clients.Client.main(Client.java:79)

Your comment brought me to a good point. I checked the ant file again and found the directory was added explicitly:

<pathelement location="${basedir}/client-config"/>

So I went to the run configuration, selected the tab "Classpath", selected User Entries, pressed "Advanced" and added the path to that dir called "client-config". And now, the initial configuration seems to work, and - eventually - it runs, but only once...

methods in TravelAgentBean:
Master Suite

I have seen the note in Chapter 24 of Enterprise JavaBeans 3.0, 5th Edition by Richard Monson-Haefel:

You cannot run this program more than once
unless you stop JBoss, clean the database by invoking the Ant task clean.db, and restart
the application server. Otherwise, you will get the following error:
[java] Exception in thread "main" java.lang.RuntimeException:
org.jboss.tm.JBossRollbackException: Unable to commit
, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=null:1099/7,
BranchQual=null:1099, localId=0:7], status=STATUS_NO_TR
ANSACTION; - nested throwable: (org.hibernate.exception.GenericJDBCException:

If I understood it correctly, you cannot execute twice, because the entries in the db are already there and do not allow a new creation.

But the error message I get is quite different. In fact it has the same error pattern as described in my other post http://www.coderanch.com/t/320810/EJB-JEE/java/invoke-method-existing-bean-JEE
and I still don't know, why the bean could be found in one run, but not in the next run.

Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
at $Proxy0.createCabin(Unknown Source)
at com.titan.clients.Client.main(Client.java:96)
Caused by: java.lang.ClassNotFoundException: [Ljava.lang.StackTraceElement;

Thanks a lot for help

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!