<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    ejb client and naming error - problem
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/darisz">Dariusz Kominek</a> in <i>EJB3</i> - <a href="https://community.jboss.org/message/776774#776774">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p><strong>I'm very beginner in ejb programming so please don't be angry if the question is easy.</strong></p><p><strong>Below is a code I wrote and it produces an error. What should I change to get this to work? I work with Eclipse Juno and JBoss 7.1.1. Below example should work for </strong></p><p>Application Server - JBoss 4.2.2 GA</p><p>IDE - Eclipse 3.4.1</p><p><strong>It doesn't work for my environment. Any help will be appreciated.</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]</p><p> at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)</p><p> at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)</p><p> at javax.naming.InitialContext.init(InitialContext.java:242)</p><p> at javax.naming.InitialContext.&lt;init&gt;(InitialContext.java:216)</p><p> at MyBeanClient.main(MyBeanClient.java:13)</p><p>Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory</p><p> at java.net.URLClassLoader$1.run(URLClassLoader.java:366)</p><p> at java.net.URLClassLoader$1.run(URLClassLoader.java:355)</p><p> at java.security.AccessController.doPrivileged(Native Method)</p><p> at java.net.URLClassLoader.findClass(URLClassLoader.java:354)</p><p> at java.lang.ClassLoader.loadClass(ClassLoader.java:423)</p><p> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)</p><p> at java.lang.ClassLoader.loadClass(ClassLoader.java:356)</p><p> at java.lang.Class.forName0(Native Method)</p><p> at java.lang.Class.forName(Class.java:264)</p><p> at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:63)</p><p> at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:671)</p><p> ... 4 more</p><p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p align="left" style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></p><p><strong>IMyBean.java</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="background-color: #cccccc;">import java.io.Serializable;</span></p><p><span style="background-color: #cccccc;">public interface IMyBean extends Serializable { </span></p><p><span style="background-color: #cccccc;">public void doSomething();</span></p><p><span style="background-color: #cccccc;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>MyBeanRemote.java</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="background-color: #cccccc;">import javax.ejb.Remote;</span></p><p><span style="background-color: #cccccc;">@Remote</span></p><p><span style="background-color: #cccccc;">public interface MyBeanRemote extends IMyBean{</span></p><p><span style="background-color: #cccccc;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>MyBeanLocal.java</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="background-color: #cccccc;">import javax.ejb.Local;</span></p><p><span style="background-color: #cccccc;">@Local</span></p><p><span style="background-color: #cccccc;">public interface MyBeanLocal extends IMyBean {</span></p><p><span style="background-color: #cccccc;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>MyBean.java</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="background-color: #cccccc;">import javax.ejb.Stateless;</span></p><p><span style="background-color: #cccccc;">@Stateless </span></p><p><span style="background-color: #cccccc;">public class MyBean implements MyBeanLocal, MyBeanRemote {</span></p><p><span style="background-color: #cccccc;">private static final long serialVersionUID = 9184424076718418234L;</span></p><p><span style="background-color: #cccccc;">public void doSomething() {</span></p><p><span style="background-color: #cccccc;">System.out.println("Hello World!"); </span></p><p><span style="background-color: #cccccc;">}</span></p><p><span style="background-color: #cccccc;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>MyBeanClient.java</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="background-color: #cccccc;">import java.util.Properties;</span></p><p><span style="background-color: #cccccc;">import javax.naming.InitialContext;</span></p><p><span style="background-color: #cccccc;">import javax.naming.NamingException;</span></p><p><span style="background-color: #cccccc;">public class MyBeanClient {</span></p><p><span style="background-color: #cccccc;">public static void main(String[] args) {</span></p><p><span style="background-color: #cccccc;">try {</span></p><p><span style="background-color: #cccccc;">Properties props = new Properties();</span></p><p><span style="background-color: #cccccc;">props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");</span></p><p><span style="background-color: #cccccc;">props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");</span></p><p><span style="background-color: #cccccc;">props.setProperty("java.naming.provider.url", "127.0.0.1:1099"); </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="background-color: #cccccc;">InitialContext ctx = new InitialContext(props); </span></p><p><span style="background-color: #cccccc;">MyBeanRemote bean = (MyBeanRemote) ctx.lookup("MyBean/remote");</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="background-color: #cccccc;">bean.doSomething();</span></p><p><span style="background-color: #cccccc;">} catch (NamingException e) {</span></p><p><span style="background-color: #cccccc;">e.printStackTrace();</span></p><p><span style="background-color: #cccccc;">} </span></p><p><span style="background-color: #cccccc;">}</span></p><p><span style="background-color: #cccccc;">}</span></p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/776774#776774">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>