  | 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
|
|
|
  | | | I can 't obtain the reference to an EJB! | I can 't obtain the reference to an EJB! 2006-02-16 - By Reydel
Back 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’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).<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> </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> </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> </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("java.naming.factory.initial" ;, “org.jnp.interfaces.NamingContextFactory");<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(" ;java.naming.provider.url",? "localhost:1099");<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(" ;java.naming.factory.url.pkgs",? "org.jboss.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> </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("Contexto Disponible");<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("Calculo ");<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("Se encontr? Referencia del EJB!");<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 "Home Interface "<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> </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 "Home Interface"<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> </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("Inter?s de 10,000 Capital, a tasa 10%, bajo 2 plazos anuales:");<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> </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>
<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> </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> </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> </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> </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>
|
|
 |