Bonjour,
Je travaille actuellement sur un projet J2EE utilisant JBoss 3.2.5. Nous utilisons des fichiers de propriétés pour configurer l'application. Le problème est que ces fichiers de propriétés sont embarqués dans le .war. Pas très pratique, me direz-vous.
Je pensais donc utiliser les MBeans pour remplacer les fichiers de propriétés.
J'ai ainsi créé une interface :
Note : mon fichier de propriétés ne contient que deux propriétés : path et nomFichier.
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 package mon.projet; import javax.naming.NamingException; public interface ProprietesFichierInterfaceMBean { public String getJndiName (); public void setJndiName (String jndiName) throws NamingException; public String getNomFichier(); public void setNomFichier(String filename); public String getPath(); public void setPath(String path); public void start() throws Exception; public void stop(); }
J'ai également codé la classe implémentant cette interface :
J'ai généré mon war. Pas de souci jusqu'ici. J'ai ensuite ajouté un fichier, proprietes-service.xml dans le répertoire deploy de JBoss :
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 package mon.projet; import java.util.HashMap; import javax.naming.InitialContext; import javax.naming.Name; import javax.naming.NamingException; import org.jboss.naming.NonSerializableFactory; public class ProprietesFichier implements ProprietesFichierInterfaceMBean { private String jndiName; private HashMap contextMap = new HashMap(); private String nomFichier; private String path; private boolean started; public String getJndiName() { return jndiName; } public void setJndiName(String jndiName) throws NamingException { String oldName = this.jndiName; this.jndiName = jndiName; if (started) { unbind(oldName); try { rebind(); } catch(Exception e) { NamingException ne = new NamingException("Failedto update jndiName"); ne.setRootCause(e); throw ne; } } } public String getNomFichier() { return nomFichier; } public void setNomFichier(String filename) { this.nomFichier = filename; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public void start() throws Exception { started = true; rebind(); } public void stop() { started = false; unbind(jndiName); } private void rebind() throws NamingException { InitialContext rootCtx = new InitialContext(); Name fullName = rootCtx.getNameParser("").parse(jndiName); System.out.println("fullName="+fullName); NonSerializableFactory.rebind(fullName, contextMap, true); } private void unbind(String jndiName) { try { InitialContext rootCtx = new InitialContext(); rootCtx.unbind(jndiName); NonSerializableFactory.unbind(jndiName); } catch(NamingException e) { e.printStackTrace(); } } }
J'ai déposé le war dans le répertoire deploy, et j'ai lancé JBoss.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <?xml version="1.0" encoding="UTF-8"?> <!--<!DOCTYPE mbean PUBLIC "-//JBoss//DTD JBOSS XMBEAN 1.1//EN" "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_1.dtd"> --> <server> <mbean code="mon.projet.ProprietesFichier" name=":service=ProprietesFichier"> <attribute name="JndiName">/jms/MyJms</attribute> <attribute name="NomFichier">batchFileError</attribute> <attribute name="Path">/tmp</attribute> <depends>jboss:service=Naming</depends> </mbean> </server>
J'obtiens alors le message suivant dans le log :
(j'ai volontairement tronqué le message d'erreur pour ne pas surcharger mon post).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 08:41:00,735 WARN [org.jboss.util.NestedThrowable] Duplicate throwable nesting of same base type: class org.jboss.deployment.DeploymentException is assignable from: class org.jboss.deployment.DeploymentException 08:41:00,737 ERROR [org.jboss.deployment.MainDeployer] could not create deployment: file:/var/jboss/server/dev4/deploy/proprietes-service.xml org.jboss.deployment.DeploymentException: create operation failed for package file:/var/jboss/server/dev4/deploy/proprietes-service.xml; - nested throwable: (org.jboss.deployment.DeploymentException: No ClassLoaders found for: mon.projet.ProprietesFichier; - nested throwable: (java.lang.ClassNotFoundException: No ClassLoaders found for: mon.projet.ProprietesFichier)) at org.jboss.deployment.SARDeployer.create(Unknown Source) at org.jboss.deployment.MainDeployer.create(Unknown Source) at org.jboss.deployment.MainDeployer.deploy(Unknown Source)
Quelqu'un a-t-il une idée de ce qui cloche ? Je pense que cela vient du fichier xml, mais je ne suis pas sur...
Merci d'avance,
Viggen
Partager