wood burning stoves
The moose likes EJB and other Java EE Technologies and the fly likes Simple Hello example for JBOSS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Simple Hello example for JBOSS" Watch "Simple Hello example for JBOSS" New topic

Simple Hello example for JBOSS

Arijit Ghosh
Ranch Hand

Joined: Feb 01, 2002
Posts: 174
I have written a simple remote interface, home interface, the bean class, the deployment descriptor and the vendoe specific xml file (all manually) to test a simple Hello World case.
Now I have created the HelloWorld.jar file with the files in its proper folders --
i.e. I kept
Hello.class (Remote interface)
HelloHome.class (Home interface)
HelloBean.class (Bean class)
within a folder called "examples" while I kept
ejb-jar.xml (Deployment descriptor)
jboss.xml (Vendor specific file)
within a folder called "META-INF"
I successfully deployed the jar file (created by jar cf HelloWorld.jar *) into the deployment directory of JBOSS.
I now have the HelloClient file.
Few points to take not of --
I am working from the folder "samples" and I have three folders "src", "examples" and "META-INF" as the sub-folders. I am using "package examples" in all the java files which are placed in the "src" folder. I have compiled the files using "java -d examples src\*.java" This resulted in the generation of the corresponding 4 class files in the "examples" folder.
Now the main file is when I am trying to execute the Client file.
I am trying to execute the following command from the "samples" folder ---
"java examples.HelloClient"
This is giving the following errors --

C:\JBoss-2.4.3_Tomcat-3.2.3\samples>java examples.HelloClient
Exception in thread "main" javax.naming.NoInitialContextException: Need to speci
fy class name in environment or system property, or as an applet parameter, or i
n an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.jav
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at examples.HelloClient.main(HelloClient.java:36)

I am listing the full codes for the 4 java files ---




Above 4 files are part from Ed Roman's book.




[ May 28, 2002: Message edited by: Arijit Ghosh ]

Regards,<br /> Arijit
jon boydell

Joined: Jul 04, 2001
Posts: 15
I think that the client can't find the directory on the jboss server to lookup the ejb. It needs to specify the url of the server and the factory to create an initial context.
Have you set up a jndi.properties file? Create one and put it in your classpath. Put the following in it:
java.naming.factory.url.pkgs=org.jboss.naming rg.jnp.interfaces
[ May 28, 2002: Message edited by: jon boydell ]
Arijit Ghosh
Ranch Hand

Joined: Feb 01, 2002
Posts: 174
Hello Jon,
Thanks for the reply. Just one clarification...
Does this mean the steps that I had listed in the problem are correct i.e. Am I doing
the steps correctly?
There is one jndi.properties file in the default conf folder. I have edited that and
included all that you have mentioned.
I tried to execute it again but the same error is shown. Is it because of the classpath
Do I have to set the classpath to "DEFAULT" folder in my Autoexec.bat file ?
Thanks in advance.
Arijit Ghosh
Ranch Hand

Joined: Feb 01, 2002
Posts: 174
C:\JBoss-2.4.3_Tomcat-3.2.3\samples>java examples.HelloClient
Exception in thread "main" javax.naming.NoInitialContextException: Cannot instan
tiate class: org.jnp.interfaces.NamingContextFactory. Root exception is java.la
ng.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:207)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.jav
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:6
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at examples.HelloClient.main(HelloClient.java:30)

When I added the following to my classpath above errors occured.
"set CLASSPATH=%CLASSPATH%;C:\JBoss-2.4.3_Tomcat-3.2.3\jboss\conf\default"
I already have the following classpath set --
"set CLASSPATH=%CLASSPATH%;C:\JBoss-2.4.3_Tomcat-3.2.3\samples\examples"
All Hello example class files are stored in the directory "examples"
And as I have mentioned before I am executing "java examples.HelloClient" from the "samples" folder.
Please help !
Arijit Ghosh
Ranch Hand

Joined: Feb 01, 2002
Posts: 174
Thanks Jon!
Got the problem... I had not included the jboss-client and jnp-client jar files in my classpath :roll: :roll:
jawwad ahmed
Ranch Hand

Joined: Dec 01, 2001
Posts: 179
if u are using jboss3.0+ go to
C:\jboss3\cong\defualt\jndi.properties uncomment the lines.
Then copy that file to the client folder.
Jawwad Ahmed
Arijit Ghosh
Ranch Hand

Joined: Feb 01, 2002
Posts: 174
If I have downloaded JBOSS 2.4.4 or 2.4.5 i.e. 2.4.x version, and have also downloaded Tomcat 4.x version separately, how can I integrate them together ?
Is it by editing the MLET code in jboss.conf file ?
It is sorta covered in the JavaRanch Style Guide.
subject: Simple Hello example for JBOSS