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 !