Visualizzazione dei risultati da 1 a 10 su 10
  1. #1

    [EJB] javax.naming.NoInitialContextException

    Ciao a tutti!
    Sto cercando di far partire questa applicazione:

    codice:
    package com.titan.clients;
    
    import com.titan.travelagent.TravelAgentRemote;
    import com.titan.domain.Cabin;
    
    import javax.naming.InitialContext;
    import javax.naming.Context;
    import javax.naming.NamingException;
    import java.util.Properties;
    import javax.rmi.PortableRemoteObject;
    
    public class Client {
        public static void main(String [] args) {
            try {
                Context jndiContext = getInitialContext( );
                Object ref = jndiContext.lookup("TravelAgentBean/remote");
                TravelAgentRemote dao = (TravelAgentRemote)
                    PortableRemoteObject.narrow(ref,TravelAgentRemote.class);
    
                Cabin cabin_1 = new Cabin( );
                cabin_1.setId(1);
                cabin_1.setName("Master Suite");
                cabin_1.setDeckLevel(1);
                cabin_1.setShipId(1);
                cabin_1.setBedCount(3);
    
                dao.createCabin(cabin_1);
    
                Cabin cabin_2 = dao.findCabin(1);
                System.out.println(cabin_2.getName( ));
                System.out.println(cabin_2.getDeckLevel( ));
                System.out.println(cabin_2.getShipId( ));
                System.out.println(cabin_2.getBedCount( ));
    
            } catch (javax.naming.NamingException ne){ne.printStackTrace( );}
        }
    
        public static Context getInitialContext( )
            throws javax.naming.NamingException {
    
            Properties p = new Properties( );
            p.put(Context.INITIAL_CONTEXT_FACTORY,
            "org.jnp.interfaces.NamingContextFactory");
            p.put(Context.URL_PKG_PREFIXES,
                " org.jboss.naming:org.jnp.interfaces");
            p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
            return new javax.naming.InitialContext(p);
        }
    }
    E' un esempio che ho trovato su un libro; Enterprise JavaBean 3.0

    Il punto è che quando faccio il RUN mi da questo errore:
    codice:
    javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
    Utilizzo NetBeans come IDE e Glassfish come Application Server;
    Sapete spiegarmi a cosa serve il metodo "lookup" e cosa è l'argomento che prende in input???

    Se qualcuno sa darmi qualche consiglio ne sarei molto grato!

  2. #2
    Utente di HTML.it L'avatar di Ed_Bunker
    Registrato dal
    Jul 2003
    Messaggi
    1,119
    Penso ti manchi una libreria a runtime.

    Il .jar org.jnp.etc ce l'hai ?!?

  3. #3
    Non so cosa sia una libreria a runtime... e non so come trovare quella che mi chiedi...

    Comunque io credo il problema stia in questi due pezzi di codice:

    codice:
                Context jndiContext = getInitialContext( );
                Object ref = jndiContext.lookup("TravelAgentBean/remote");
    codice:
    public static Context getInitialContext( )
            throws javax.naming.NamingException {
    
            Properties p = new Properties( );
            p.put(Context.INITIAL_CONTEXT_FACTORY,
            "org.jnp.interfaces.NamingContextFactory");
            p.put(Context.URL_PKG_PREFIXES,
                " org.jboss.naming:org.jnp.interfaces");
            p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
            return new javax.naming.InitialContext(p);
    }
    Credo che questo codice vada bene per JBoss AP ma non per Glassfish(Sun Java System Application Server 9.1).
    Io come ho scritto su utilizzo NetBeans con Glassfish. Cercando su internet ho trovato questo tutorial:
    Tutorial J2EE
    Non lo ho ancora letto e studiato, ma credo possa aiutarmi ha capire come sviluppare Enterprise Application con NetBeans e Glassfish. Ho avuto notevoli problemi in quanto tutti i forum, con le relative guide, sono monopolizzati da JBoss.

  4. #4
    Se qualcuno sa indicarmi altre guide su EJB 3.0 utilizzando, però, netbeans e glassfish, ne sarei molto grato.

    Grazie!

  5. #5
    Utente di HTML.it L'avatar di Ed_Bunker
    Registrato dal
    Jul 2003
    Messaggi
    1,119
    Mi sembra che QUA sia descritto bene il problema da te riscontrato.

  6. #6
    Forse non mi sono spiegato granché:
    Credo che le due parti di codice su scritte siano specifiche per ogni application server, almeno così ho letto sul libro che sto studiando... il punto è che il libro fa gli esempi utilizzando JBoss, mentre io voglio usare Glassfish!!!

    Il libro, parlando della classe clients che ho scritto su, dice:
    codice:
    To access an enterprise bean, a client starts by using JNDI to obtain a directory connection to a bean's container. JNDI is an implementation-independent API for directory and naming systems. Every EJB vendor must provide a directory service that is JNDI-compliant. This means that they must provide a JNDI service provider, which is a piece of software analogous to a driver in JDBC. Different service providers connect to different directory servicesnot unlike JDBC, where different drivers connect to different relational databases. The getInitialContext( ) method uses JNDI to obtain a network connection to the EJB server.
    
    The code used to obtain a JNDI context depends on which EJB vendor you use. Consult your vendor's documentation to find out how to obtain a JNDI context appropriate to your product. For example, the code used to obtain a JNDI context in WebSphere might look something like the following:
    
    public static Context getInitialContext( )
        throws javax.naming.NamingException {
    
        java.util.Properties properties = new java.util.Properties( );
        properties.put(javax.naming.Context.PROVIDER_URL, "iiop:///");
        properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
            "com.ibm.ejs.ns.jndi.CNInitialContextFactory");
        return new InitialContext(properties);
    }
    
    
    
    The same method developed for JBoss would be different:
    
    public static Context getInitialContext( )
        throws javax.naming.NamingException {
    
        Properties p = new Properties( );
        p.put(Context.INITIAL_CONTEXT_FACTORY,
            "org.jnp.interfaces.NamingContextFactory");
        p.put(Context.URL_PKG_PREFIXES,
            " org.jboss.naming:org.jnp.interfaces");
        p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
        return new javax.naming.InitialContext(p);
    }
    E' probabile che non abbia il package che mi hai chiesto prima, se esso è compreso in JBoss. Questo perchè io non ho installato JBoss!
    Grazie dell'interessamento comunque!

  7. #7
    Prova a vedere se qui c'è qualcosa che ti torna utile.

    Al mio segnale... scatenate l'inferno!

  8. #8
    Grazie dell'aiuto!!! Il link che mi hai dato non è male... ma dovrei già conoscere gli Enterprise JavaBean. In realtà è qesto il mio problema non conosco quello di cui sto parlando.

    Ho trovato questo libro sul sito della sun:
    java ee 5 tutorial

    Mi sa che me lo devo studiare se voglio combinare qualcosa... almeno la parte sugli EJB.

    Devo imparare a sviluppare Enterprise Applications utilizzando gli 'entity bean' e i 'session bean'. Devo collegare gli 'entity bean' ad un database, e devo fare delle pagine JSP, come interfaccia per i client, che si appaggiano a delle servlet.
    Ho deciso di utilizzare Glassfish e NetBeans, come ho più volte ripetuto, ma non so ancora a che tipo di database appoggiarmi.
    Su servlet e JSP non ho problemi... ma devo imparare EJB 3.0 e come collegarli ad un database.
    Penso che la guida su faccia al caso mio... anche se la avrei preferita in italiano!

  9. #9
    Allora prova la guida che c'è su html.it (4° paragrafo) oppure qui. Entrambe non usano Glassfish però seguendo anche quel tutorial che ti ho postato prima puoi facilmente adattarle.
    Al mio segnale... scatenate l'inferno!

  10. #10
    OK... Grazie!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.