I have the following structure
MyProject.ear (module name) MyProjectEar
|----- lib
|----- META-INF
|----- MyProject.war
|----- MyProject.jar (module name) MyProject
At MyProject.jar I have several EJBs, including a mypackages.myproject.ejb.impl.ConfigManager
(which has a local interface in mypackages.myproject.ejb.local.ConfigManagerLocal
)
ConfigManager
@Singleton
@Startup
public class GestorConfiguracion implements GestorConfiguracionLocal {
@PostConstruct
private void init() {
Context ctx = null;
try {
ctx = new InitialContext();
ctx = (Context) ctx.lookup("java:comp");
} catch (Exception e) {
return;
}
try {
String jndiEnv = (String) ctx.lookup("myProject/srv/environment");
} catch (Exception e) {
log.log(Level.WARNING, "Exception in jndienv", e);
}
try {
appVersion = (String) ctx.lookup("myProject/buildVersion"));
} catch (Exception e) {
log.log(Level.WARNING, "Exception in buildversion", e);
}
myProject/srv/environment
is to be local to the server (so it does not change between EAR builds), so it is set in standalone.xml
, as follows
<subsystem xmlns="urn:jboss:domain:naming:2.0">
<bindings>
<simple name="java:/env/myProject/srv/environment" value="DEV"/>
</bindings>
<remote-naming/>
</subsystem>
myProject/buildVersion
will be changed at each building, by adding an env-entry-value
to the env-entry
.
I have tried two approachs:
1) Add to MyProject.ear/META-INF/application.xml the lines:
<env-entry>
<env-entry-name>myProject/buildVersion</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>0.0.1</env-entry-value>
</env-entry>
<resource-ref>
<res-ref-name>myProject/srv/environment</res-ref-name>
<res-type>java.lang.String</res-type>
<lookup-name>java:/env/myProject/srv/environment</lookup-name>
</resource-ref>
I only get javax.naming.NameNotFoundException
, with the messages:
service jboss.naming.context.java.comp.MyProjectEar.MyProject.ConfigManager.myProject.buildVersion
service jboss.naming.context.java.comp.MyProjectEar.MyProject.ConfigManager.myProject.srv.environment