• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setting up jndi properties in eclipse 3.3.2

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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:

<classpath>
<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;
try
{
context = new InitialContext(properties);
Object ref = context.lookup("TravelAgentBean/remote");

with

Properties properties = new Properties();
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"
);
properties.put("java.naming.factory.url.pkgs","=org.jboss.naming rg.jnp.interfaces");
properties.put("java.naming.provider.url","localhost:1099");

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"/>
</java>
</target>

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

Thanks for help

Markus
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...

(output)
methods in TravelAgentBean:
...
remove
createCabin
findCabin
...
Master Suite
1
1
3



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:
run.client:
[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 https://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

Markus
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic