IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Wildfly/JBoss Java Discussion :

Execution d'un client riche pour EJB


Sujet :

Wildfly/JBoss Java

  1. #1
    Membre actif

    Inscrit en
    Juin 2003
    Messages
    229
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Juin 2003
    Messages : 229
    Points : 223
    Points
    223
    Par défaut Execution d'un client riche pour EJB
    Bonjour,

    Je travaille sous JBoss 4.0.4.GA, eclipse 3.2 WTP, ubuntu dapper drake.

    J'ai développé un EJB session stateless à l'aide d'eclipse. Tout se passe très bien, j'arrive à déployer l'ejb, un servlet permettant de tester que tout se passe bien, et également un client riche (qui se contente d'un affichage dans une console).

    Lorsque je lance le client riche sous eclipse, l'execution se passe bien, avec le bon résultat. Je souhaite maintenant créer un Jar Application Client pour éviter d'utiliser eclipse pour lancer l'application, et là, ça se gate : voici l'erreur que j'obtient :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]
            at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
            at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
            at javax.naming.InitialContext.init(InitialContext.java:223)
            at javax.naming.InitialContext.<init>(InitialContext.java:175)
            at client.Main.main(Main.java:16)
    Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
    Il semblerait que ce problème vient du fait qu'il n'y a pas jbossall-client.jar dans le classpath. Mais pourquoi cela fonctionne-t-il dans Eclipse ?

    Voici le code des classes que j'utilise :
    (l'EJB se nomme Hello, dans le projet TestJ)

    Hello.java :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
    /*
     * Generated by XDoclet - Do not edit!
     */
    package ejb;
     
    /**
     * Remote interface for Hello.
     * @generated 
     * @wtp generated
     */
    public interface Hello
       extends javax.ejb.EJBObject
    {
       /**
        * <!-- begin-xdoclet-definition -->
        * @generated //TODO: Must provide implementation for bean method stub    */
       public java.lang.String foo( java.lang.String param )
          throws java.rmi.RemoteException;
     
       /**
        * <!-- begin-xdoclet-definition -->
        */
       public java.lang.String hello(  )
          throws java.rmi.RemoteException;
     
    }
    HelloHome.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    /*
     * Generated by XDoclet - Do not edit!
     */
    package ejb;
     
    /**
     * Home interface for Hello.
     * @generated 
     * @wtp generated
     */
    public interface HelloHome
       extends javax.ejb.EJBHome
    {
       public static final String COMP_NAME="java:comp/env/ejb/Hello";
       public static final String JNDI_NAME="Hello";
     
       public ejb.Hello create()
          throws javax.ejb.CreateException,java.rmi.RemoteException;
     
    }
    HelloBean.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
     
    /**
     * 
     */
    package ejb;
     
    import java.rmi.RemoteException;
     
    import javax.ejb.EJBException;
    import javax.ejb.SessionContext;
     
     
    /**
     *
     * <!-- begin-user-doc -->
     * A generated session bean
     * <!-- end-user-doc -->
     * *
     * <!-- begin-xdoclet-definition --> 
     * @ejb.bean name="Hello"       
     *           description="An EJB named Hello"
     *           display-name="Hello"
     *           jndi-name="Hello"
     *           type="Stateless" 
     *           transaction-type="Container"
     * 
     * <!-- end-xdoclet-definition --> 
     * @generated
     */
     
    public class HelloBean implements javax.ejb.SessionBean {
     
    	/** 
             *
             * <!-- begin-xdoclet-definition --> 
             * @ejb.create-method view-type="remote"
             * <!-- end-xdoclet-definition --> 
             * @generated
             *
             * //TODO: Must provide implementation for bean create stub
             */
    	public void ejbCreate() {
    	}
     
    	/** 
             *
             * <!-- begin-xdoclet-definition --> 
             * @ejb.interface-method view-type="remote"
             * <!-- end-xdoclet-definition --> 
             * @generated
             *
             * //TODO: Must provide implementation for bean method stub
             */
    	public String foo(String param) {
    		return null;
    	}
     
    	/**
              * <!-- begin-xdoclet-definition -->
              * @ejb.interface-method view-type="remote"
              * <!-- end-xdoclet-definition -->
              */
    	public String hello() {
    		return "hello";
    	}
     
    	/* (non-Javadoc)
    	 * @see javax.ejb.SessionBean#ejbActivate()
    	 */
    	public void ejbActivate() throws EJBException, RemoteException {
    		// TODO Auto-generated method stub
     
    	}
     
    	/* (non-Javadoc)
    	 * @see javax.ejb.SessionBean#ejbPassivate()
    	 */
    	public void ejbPassivate() throws EJBException, RemoteException {
    		// TODO Auto-generated method stub
     
    	}
     
    	/* (non-Javadoc)
    	 * @see javax.ejb.SessionBean#ejbRemove()
    	 */
    	public void ejbRemove() throws EJBException, RemoteException {
    		// TODO Auto-generated method stub
     
    	}
     
    	/* (non-Javadoc)
    	 * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
    	 */
    	public void setSessionContext(SessionContext arg0) throws EJBException,
    			RemoteException {
    		// TODO Auto-generated method stub
     
    	}
     
    	/**
             * 
             */
    	public HelloBean() {
    		// TODO Auto-generated constructor stub
    	}
    }
    Servlet : HelloServlet.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
     
    /**
     * 
     */
    package ejb;
     
    import java.rmi.RemoteException;
     
    import javax.ejb.EJBException;
    import javax.ejb.SessionContext;
     
     
    /**
     *
     * <!-- begin-user-doc -->
     * A generated session bean
     * <!-- end-user-doc -->
     * *
     * <!-- begin-xdoclet-definition --> 
     * @ejb.bean name="Hello"       
     *           description="An EJB named Hello"
     *           display-name="Hello"
     *           jndi-name="Hello"
     *           type="Stateless" 
     *           transaction-type="Container"
     * 
     * <!-- end-xdoclet-definition --> 
     * @generated
     */
     
    public class HelloBean implements javax.ejb.SessionBean {
     
    	/** 
             *
             * <!-- begin-xdoclet-definition --> 
             * @ejb.create-method view-type="remote"
             * <!-- end-xdoclet-definition --> 
             * @generated
             *
             * //TODO: Must provide implementation for bean create stub
             */
    	public void ejbCreate() {
    	}
     
    	/** 
             *
             * <!-- begin-xdoclet-definition --> 
             * @ejb.interface-method view-type="remote"
             * <!-- end-xdoclet-definition --> 
             * @generated
             *
             * //TODO: Must provide implementation for bean method stub
             */
    	public String foo(String param) {
    		return null;
    	}
     
    	/**
              * <!-- begin-xdoclet-definition -->
              * @ejb.interface-method view-type="remote"
              * <!-- end-xdoclet-definition -->
              */
    	public String hello() {
    		return "hello";
    	}
     
    	/* (non-Javadoc)
    	 * @see javax.ejb.SessionBean#ejbActivate()
    	 */
    	public void ejbActivate() throws EJBException, RemoteException {
    		// TODO Auto-generated method stub
     
    	}
     
    	/* (non-Javadoc)
    	 * @see javax.ejb.SessionBean#ejbPassivate()
    	 */
    	public void ejbPassivate() throws EJBException, RemoteException {
    		// TODO Auto-generated method stub
     
    	}
     
    	/* (non-Javadoc)
    	 * @see javax.ejb.SessionBean#ejbRemove()
    	 */
    	public void ejbRemove() throws EJBException, RemoteException {
    		// TODO Auto-generated method stub
     
    	}
     
    	/* (non-Javadoc)
    	 * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
    	 */
    	public void setSessionContext(SessionContext arg0) throws EJBException,
    			RemoteException {
    		// TODO Auto-generated method stub
     
    	}
     
    	/**
             * 
             */
    	public HelloBean() {
    		// TODO Auto-generated constructor stub
    	}
    }
    Client riche : Main.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
    package client;
     
    import ejb.Hello;
    import ejb.HelloHome;
    import javax.naming.InitialContext;
    import javax.rmi.PortableRemoteObject;
     
    public class Main {
     
    	/**
             * @param args
             */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		try{
    			InitialContext jndiContext = new InitialContext();
    			Object ref = jndiContext.lookup("Hello");
    			HelloHome home = (HelloHome)PortableRemoteObject.narrow(ref, HelloHome.class);
    			Hello hello = home.create();
     
    			System.out.println(hello.hello());
    		}catch (Exception e){
    			e.printStackTrace();
    		}
    	}
     
    }
    MANIFEST.MF de TestJClient.jar
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    Manifest-Version: 1.0
    Class-Path: TestJEJB.jar
    Main-Class: client.Main
    Merci !

  2. #2
    ego
    ego est déconnecté
    Rédacteur

    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Juillet 2004
    Messages
    1 883
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Architecte de système d'information
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 883
    Points : 3 510
    Points
    3 510
    Billets dans le blog
    2
    Par défaut
    Sous Eclipse (dans ton projet), tu as peut être les jars de JBoss qui contiennent déjà l'implémentation JNDI de JBoss. Le jbossall-client est une version juste nécessaire pour un client type riche.

Discussions similaires

  1. Client Swing pour un EJB
    Par mysianne dans le forum Java EE
    Réponses: 2
    Dernier message: 04/04/2013, 15h45
  2. Réponses: 1
    Dernier message: 24/10/2006, 00h24
  3. [EJB2] Sources de données pour EJB
    Par thomy dans le forum Java EE
    Réponses: 4
    Dernier message: 04/06/2003, 15h52
  4. Réponses: 9
    Dernier message: 24/05/2003, 10h25
  5. Client C pour CORBA
    Par rv dans le forum CORBA
    Réponses: 3
    Dernier message: 06/05/2002, 11h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo