Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Subject: Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Subject: Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
I can 't obtain the reference to an EJB!

I can 't obtain the reference to an EJB!

2006-02-16       - By Reydel

 Back
Reply:     1     2     3  

  Hi, I?m a new one working with J2EE. I?m developing an application and I
need to access the EJBs from my client (a Java application).

  This is the code of my client (a test one):



package clients;

import java.util.Properties;
import javax.rmi.PortableRemoteObject;
import javax.naming.*;

class Client
{
   public static void main(String[] args)
   {
      Properties env = new Properties();
     
      // Define properties and JNDI names lookup location.
      env.setProperty("java.naming.factory.initial",
?org.jnp.interfaces.NamingContextFactory");
      env.setProperty("java.naming.provider.url",  "localhost:1099");
      env.setProperty("java.naming.factory.url.pkgs",  "org.jboss.naming");

      try
      {
         // Bring the name context
         InitialContext jndiContext = new InitialContext(env);
         System.out.println("Contexto Disponible");
         
         // Bring the referente to the EJB
         Object ref  = jndiContext.lookup("Calculo");
         System.out.println("Se encontr? Referencia del EJB!");
         
         // Bring the referente to the "Home Interface "
         InteresesHome home = (InteresesHome)
         PortableRemoteObject.narrow (ref, InteresesHome.class);

         // Create an object from the "Home Interface"
         Intereses interes = home.create();

         // Call the function
         System.out.println("Inter?s de 10,000 Capital, a tasa 10%, bajo 2
plazos anuales:");
         System.out.println(interes.calcularInteres(10000, 0.10, 2));
      }
      catch(Exception e)
      {
         System.out.println(e.toString());
      }
   }
}



When I execute this, there is an error. It says:
javax.naming.NoInitialContextException: Cannot instantiate class:
org.jnp.interfaces.NamingContextFactory [Root exception is
java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]


Would some of you be so kind to help me fixing that? What sould I do?








===========================================================================
To unsubscribe, send email to listserv@(protected) and include in the body
of the message "signoff J2EE-INTEREST".  For general help, send email to
listserv@(protected) and include in the body of the message "help".


<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas
-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=iso-8859 (See http://iso-8859.ora-code.com)-1">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
       {margin:0in;
       margin-bottom:.0001pt;
       font-size:12.0pt;
       font-family:"Times New Roman";}
a:link, span.MsoHyperlink
       {color:blue;
       text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
       {color:purple;
       text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
       {margin:0in;
       margin-bottom:.0001pt;
       font-size:10.0pt;
       font-family:"Courier New";}
p.MsoAutoSig, li.MsoAutoSig, div.MsoAutoSig
       {margin:0in;
       margin-bottom:.0001pt;
       font-size:12.0pt;
       font-family:"Times New Roman";}
pre
       {margin:0in;
       margin-bottom:.0001pt;
       font-size:10.0pt;
       font-family:"Courier New";}
span.EstiloCorreo17
       {mso-style-type:personal-compose;
       font-family:Arial;
       color:windowtext;}
@(protected) Section1
       {size:595.3pt 841.9pt;
       margin:70.85pt 85.05pt 70.85pt 85.05pt;}
div.Section1
       {page:Section1;}
-->
</style>

</head>

<body lang=ES link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><font size=2 face=Arial><span lang=EN-US style='font-size:
10.0pt;font-family:Arial'>?? Hi, I&#8217;m a new one working with J2EE. I&#8217
;m
developing an application and I need to access the EJBs from my client (a Java
application).<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-align:justify'><font size=2 face=Arial><span
lang=EN-US style='font-size:10.0pt;font-family:Arial'>?? This is the code of my
client (a test one):<o:p></o:p></span></font></p>

<p class=MsoNormal style='text-align:justify'><font size=2 face=Arial><span
lang=EN-US style='font-size:10.0pt;font-family:Arial'><o:p>&nbsp;</o:p></span><
/font></p>

<pre style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'>package clients;<o:p></o:p><
/span></font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'><o:p>&nbsp;</o:p></span></font><
/pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'>import java.util.Properties;<o:p
></o:p></span></font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'>import javax.rmi
.PortableRemoteObject; <o:p></o:p></span></font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'>import javax.naming.*;<o:p></o:p
></span></font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'><o:p>&nbsp;</o:p></span></font><
/pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'>class Client<o:p></o:p></span><
/font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'> {<o:p></o:p></span></font></pre
><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'>??? public static void main
(String[] args)<o:p></o:p></span></font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'>??? </span>{<o:p></o:p></font><
/pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
style='font-size:10.0pt;color:navy'>?????? Properties env = new Properties();<o
:p></o:p></span></font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
style='font-size:10.0pt;color:navy'>?? ????<o:p></o:p></span></font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'>???????</span></font><font
color=green><span lang=EN-US style='color:green'>// Define properties and JNDI
names lookup location.<o:p></o:p></span></font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'>?????? <b><span
style='font-weight:bold'>env.setProperty(&quot;java.naming.factory.initial&quot
;, &#8220;org.jnp.interfaces.NamingContextFactory&quot;);<o:p></o:p></span></b><
/span></font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'>?????? env.setProperty(&quot
;java.naming.provider.url&quot;,? &quot;localhost:1099&quot;);<o:p></o:p></span>
</font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'>????? ?env.setProperty(&quot
;java.naming.factory.url.pkgs&quot;,? &quot;org.jboss.naming&quot;);<o:p></o:p><
/span></font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'><o:p>&nbsp;</o:p></span></font><
/pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'>?????? </span>try<o:p></o:p><
/font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
style='font-size:10.0pt;color:navy'>?????? {</span></font><font color=green>
<span
style='color:green'><o:p></o:p></span></font></pre><pre style='text-align
:justify'><font
size=2 color=green face="Courier New"><span style='font-size:10.0pt;color:green
'>????????? // Bring the name context<o:p></o:p></span></font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
style='font-size:10.0pt;color:navy'>????????? </span></font><font color=navy>
<span
lang=EN-US style='color:navy'>InitialContext jndiContext = new InitialContext
(env);<o:p></o:p></span></font></pre><pre
style='text-align:justify'><font size=2 color=navy face="Courier New"><span
lang=EN-US style='font-size:10.0pt;color:navy'>????????? </span>System.out
.println(&quot;Contexto Disponible&quot;);<o:p></o:p></font></pre><pre><font
size=2 color=navy face="Courier New"><span style='font-size:10.0pt;color:navy'>
???? ?????<o:p></o:p></span></font></pre><pre><font
size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
color:navy'>??????????</span></font><font color=green><span lang=EN-US
style='color:green'>// Bring the referente to the EJB<o:p></o:p></span></font><
/pre><pre><font
size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
color:navy'>????????? </span>Object ref? = jndiContext.lookup(&quot;Calculo
&quot;);<o:p></o:p></font></pre><pre><font
size=2 color=navy face="Courier New"><span style='font-size:10.0pt;color:navy'>
????????? System.out.println(&quot;Se encontr? Referencia del EJB!&quot;);<o:p><
/o:p></span></font></pre><pre><font
size=2 color=navy face="Courier New"><span style='font-size:10.0pt;color:navy'>
????????? <o:p></o:p></span></font></pre><pre><font
size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
color:navy'>??????????</span></font><font color=green><span lang=EN-US
style='color:green'>// Bring the referente to the &quot;Home Interface &quot;<o
:p></o:p></span></font></pre><pre><font
size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
color:navy'>????????? InteresesHome home = (InteresesHome) <o:p></o:p></span><
/font></pre><pre><font
size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
color:navy'>??????????PortableRemoteObject.narrow (ref, InteresesHome.class);<o
:p></o:p></span></font></pre><pre><font
size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
color:navy'><o:p>&nbsp;</o:p></span></font></pre><pre><font size=2 color=green
face="Courier New"><span lang=EN-US style='font-size:10.0pt;color:green'>??????
??? // Create an object from the &quot;Home Interface&quot;<o:p></o:p></span><
/font></pre><pre><font
size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
color:navy'>????????? </span>Intereses interes = home.create();<o:p></o:p><
/font></pre><pre><font
size=2 color=navy face="Courier New"><span style='font-size:10.0pt;color:navy'>
<o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=navy face="Courier New"><span style='font-size:10.0pt;color:navy'>
????????? </span></font><font
color=green><span style='color:green'>// Call the function <o:p></o:p></span><
/font></pre><pre><font
size=2 color=navy face="Courier New"><span style='font-size:10.0pt;color:navy'>
??????????System.out.println(&quot;Inter?s de 10,000 Capital, a tasa 10%, bajo 2
plazos anuales:&quot;);<o:p></o:p></span></font></pre><pre><font
size=2 color=navy face="Courier New"><span style='font-size:10.0pt;color:navy'>
????????? </span></font><font
color=navy><span lang=EN-US style='color:navy'>System.out.println(interes
.calcularInteres(10000, 0.10, 2));<o:p></o:p></span></font></pre><pre><font
size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
color:navy'>?????? }<o:p></o:p></span></font></pre><pre><font size=2
color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
color:navy'>?????? catch(Exception e)<o:p></o:p></span></font></pre><pre><font
size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
color:navy'>?????? {<o:p></o:p></span></font></pre><pre><font size=2
color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
color:navy'>????????? System.out.println(e.toString());<o:p></o:p></span></font
></pre><pre><font
size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
color:navy'>?????? </span>}<o:p></o:p></font></pre><pre><font size=2
color=navy face="Courier New"><span style='font-size:10.0pt;color:navy'>??? }<o
:p></o:p></span></font></pre><pre><font
size=2 color=navy face="Courier New"><span style='font-size:10.0pt;color:navy'>
}<o:p></o:p></span></font></pre><pre><font
size=2 color=navy face="Courier New"><span style='font-size:10.0pt;color:navy'>
<o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 color=navy face="Courier New"><span style='font-size:10.0pt;color:navy'>
<o:p>&nbsp;</o:p></span></font></pre>

<p class=MsoNormal style='text-autospace:none'><b><font size=3 color=navy
face="Times New Roman"><span lang=EN-US style='font-size:12.0pt;color:navy;
font-weight:bold'>When I execute this, there is an error. It says</span></font>
</b><font
color=navy><span lang=EN-US style='color:navy'>:? ?</span></font><u><font
size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
font-family:"Courier New";color:navy;background:white'>javax.naming
.NoInitialContextException</span></font></u><font
size=2 color=black face="Courier New"><span lang=EN-US style='font-size:10.0pt;
font-family:"Courier New";color:black;background:white'>: Cannot instantiate
class: org.jnp.interfaces.NamingContextFactory [Root exception is </span></font
><u><font
size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
font-family:"Courier New";color:navy;background:white'>java.lang
.ClassNotFoundException</span></font></u><font
size=2 color=black face="Courier New"><span lang=EN-US style='font-size:10.0pt;
font-family:"Courier New";color:black;background:white'>:
org.jnp.interfaces.NamingContextFactory]</span></font><font size=2
face="Courier New"><span lang=EN-US style='font-size:10.0pt;font-family:
"Courier New"'><o:p></o:p></span></font></p>

<pre><font size=2 color=navy face="Courier New"><span lang=EN-US
style='font-size:10.0pt;color:navy'><o:p>&nbsp;</o:p></span></font></pre><pre>
<b><font
size=2 color=navy face="Courier New"><span lang=EN-US style='font-size:10.0pt;
color:navy;font-weight:bold'>Would some of you be so kind to help me fixing
that? What sould I do?<o:p></o:p></span></font></b></pre>

<p class=MsoNormal><font size=2 face=Arial><span lang=EN-US style='font-size:
10.0pt;font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span lang=EN-US style='font-size:
10.0pt;font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span lang=EN-US style='font-size:
10.0pt;font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>
===========================================================================
To unsubscribe, send email to listserv@(protected) and include in the body
of the message "signoff J2EE-INTEREST".  For general help, send email to
listserv@(protected) and include in the body of the message "help".
<p>

©2008 junlu.com - Jax Systems, LLC, U.S.A.