Table of Contents
Create and verify the related String Object in JNDI:
Remove the JNDI String object [ only if already created ] [oracle@wls1 JNDI]$ $WILDFLY_HOME/bin/jboss-cli.sh --connect "/subsystem=naming/binding=java\:global\/mystring/:remove" [oracle@wls1 JNDI]$ $WILDFLY_HOME/bin/jboss-cli.sh --connect reload Create JNDI String object [oracle@wls1 JNDI]$ cat new_jndi.cli /subsystem=naming/binding=java\:global\/mystring/:add(binding-type=simple,value="My JNDI strored String",type=java.lang.String) [oracle@wls1 JNDI]$ $WILDFLY_HOME/bin/jboss-cli.sh --connect --file=new_jndi.cli {"outcome" => "success"} Verify wiht JNDI view: [oracle@wls1 JNDI]$ $WILDFLY_HOME/bin/jboss-cli.sh --connect "/subsystem=naming:jndi-view" ... "java:global" => { "mystring" => { "class-name" => "java.lang.String", "value" => "My JNDI strored String" },
Java Code reading our JNDI String entry
1) Initialize a String via JNDI and Annotations: @Resource(lookup = "java:global/mystring") private String myString ; 2) Initialize a String via JNDI and Context lookup: InitialContext ctx = new InitialContext(); System.out.println("--> Following shows Looking up a Primitive Datatype located in the JNDI ***"); Object primitiveLookup=ctx.lookup("java:global/mystring"); System.out.println("ic.lookup(java:global/mystring) - primitiveLookup = " + primitiveLookup); setMyStringCtx((String)primitiveLookup); System.out.println("String Initialization via JNDI and Context lookup: " + myStringCtx ); Output Wildfly Server : 14:03:01,562 INFO [stdout] (default task-4) String Initialization via JNDI and Annotation : My JNDI strored String 14:03:01,562 INFO [stdout] (default task-4) --> Following shows Looking up a Primitive Datatype located in the JNDI *** 14:03:01,563 INFO [stdout] (default task-4) ic.lookup(java:global/mystring) - primitiveLookup = My JNDI strored String 14:03:01,563 INFO [stdout] (default task-4) String Initialization via JNDI and Context lookup: My JNDI strored String
Download location for Source Code
JAVA Source : jndiBean.java JSF Source : index.xhtml