简单办法,COPY这个文件重命名,修改相应的JNDI名,则OK啦

解决方案 »

  1.   

    deploy下所放的都是部署文件,楼主所说的是配置数据库连接,在docs\examples\jca下的都是相应的数据库连接设置文件,你COPY到deploy下,修改相应的JNDI名,则实现了数据库连接设置了
      

  2.   

    楼上的两位,楼主的意思,似乎是要部署一个自己定义的配置文件,由配置文件提供环境变量信息,请看这一段:
    我需要在服务器上绑定一个自定义的jndi,类似与这样:
      <jndi-name>MyJNDI</jndi-name>
      <jndi-value>abcdefg</jndi-value>
    jboss支持外部扩展文件的自定义部署,但具体用什么类就不知道了.。楼主查文档也许能找到。祝好运!
    楼下的继续
      

  3.   

    楼主请看这一段说明:
    Additional Naming MBeans
    In addition to the NamingService MBean that configures an embedded JBossNS server within JBoss, there are three other MBean services related to naming that ship with JBoss:ExternalContext, NamingAlias, and JNDIView.The org.jboss.naming.ExternalContext MBean
    The ExternalContext MBean allows you to federate external JNDI contexts into the JBoss server JNDI namespace. The term external refers to any naming service external to the JBossNS naming service running inside the JBoss server VM. You can incorporate LDAP servers, file systems, DNS servers, and so on, even if the JNDI provider root context is not serializable. The federation can be made available to remote clients if the naming service supports remote access.To incorporate an external JNDI naming service, you have to add a configuration of the ExternalContext MBean service to the jboss-service.xml configuration file. The configurable attributes of the ExternalContext service are as follows:JndiName The JNDI name under which the external context is to be bound.RemoteAccess A Boolean flag that indicates whether the external InitialContext should be bound using a Serializable form that allows a remote client to create the external InitialContext. When a remote client looks up the external context via the JBoss JNDI InitialContext, the client effectively creates an instance of the external InitialContext, using the same env properties passed to the ExternalContext MBean. This works only if the client can do a new InitialContext (env) remotely. This requires that the Context.PROVIDER_URL value of env be resolvable in the remote VM that is accessing the context. This should work for the LDAP example. For the file system example, this most likely won't work unless the file system path refers to a common network path. If this property is not given, it defaults to false.CacheContext The cacheContext flag. When it is set to true, the external context is created only when the MBean is started, and then it is stored as an in-memory object until the MBean is stopped. If cacheContext is set to false, the external Context is created on each lookup, using the MBean properties and InitialContext class. When a client looks up the uncached context, the client should invoke close() on the context to prevent resource leaks.InitialContext The fully qualified classname of the InitialContext implementation to use. It must be one of these: javax.naming.InitialContext, javax.naming.directory.InitialDirContext, or javax.naming.ldap.InitialLdapContext. In the case of InitialLdapContext, a null Controls array is used. The default is javax.naming.InitialContext.Properties The JNDI properties for the external InitialContext. The input should be the text equivalent of what would go into a jndi.properties file.PropertiesURL The jndi.properties information for the external InitialContext from an external properties file. This is either a URL, a string, or a classpath resource name. The following are some examples:file:///config/myldap.propertieshttp://config.mycompany.com/myldap.properties/conf/myldap.propertiesmyldap.propertiesThe following MBean definition shows a binding to an external LDAP context into the JBoss JNDI namespace under the name external/ldap/jboss:<!-- Bind a remote LDAP server -->
    <mbean code="org.jboss.naming.ExternalContext"
           name="jboss.jndi:service=ExternalContext,jndiName=external/ldap/jboss">
        <attribute name="JndiName">external/ldap/jboss</attribute>
        <attribute name="Properties">
            java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory
            java.naming.provider.url=ldap://ldaphost.jboss.org:389/o=jboss.org
            java.naming.security.principal=cn=Directory Manager
            java.naming.security.authentication=simple
            java.naming.security.credentials=secret
        </attribute>
        <attribute name="InitialContext"> javax.naming.ldap.InitialLdapContext
    </attribute>
        <attribute name="RemoteAccess">true</attribute>
    </mbean>With this configuration, you can access the external LDAP context located at ldap://ldaphost.jboss.org:389/o=jboss.org from within the JBoss VM by using the following code fragment:InitialContext iniCtx = new InitialContext();
    LdapContext ldapCtx = iniCtx.lookup("external/ldap/jboss");Using the same code fragment outside the JBoss server VM would work in this case because the RemoteAccess property is set to true. If it were set to false, it would not work because the remote client would receive a Reference object with an ObjectFactory that would not be able to re-create the external InitialContext:<!-- Bind the /usr/local file system directory -->
    <mbean code="org.jboss.naming.ExternalContext"
           name="jboss.jndi:service=ExternalContext,jndiName=external/fs/usr/local">
        <attribute name="JndiName">external/fs/usr/local</attribute>
        <attribute name="Properties">
            java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory
            java.naming.provider.url=file:///usr/local
        </attribute>
        <attribute name="InitialContext">javax.naming.InitialContext</attribute>
    </mbean>This configuration describes binding a local file system directory /usr/local into the JBoss JNDI namespace under the name external/fs/usr/local.With this configuration, you can access the external file system context located at the file ///usr/local from within the JBoss VM, using the following code fragment:InitialContext iniCtx = new InitialContext();
    Context ldapCtx = iniCtx.lookup("external/fs/usr/local");Note that this code uses one of the Sun JNDI service providers, which must be downloaded from http://java.sun.com/products/jndi/serviceproviders.html. The provider JARs should be placed in the server configuration lib directory.The org.jboss.naming.NamingAlias MBean
    The NamingAlias MBean is a simple utility service that allows you to create an alias in the form of a JNDI javax.naming.LinkRef from one JNDI name to another. This is similar to a symbolic link in the Unix file system. To an alias you add a configuration of the NamingAlias MBean to the jboss-service.xml configuration file.The configurable attributes of the NamingAlias service are as follows:FromName The location where the LinkRef is bound under JNDI.ToName The to name of the alias. This is the target name to which the LinkRef refers. The name is a URL, or a name to be resolved relative to the InitialContext; or if the first character of the name is a dot (.), the name is relative to the context in which the link is bound.The following example provides a mapping of the JNDI name QueueConnectionFactory to the name ConnectionFactory:<mbean code="org.jboss.naming.NamingAlias"
           name="jboss.mq:service=NamingAlias,fromName=QueueConnectionFactory">
        <attribute name="ToName">ConnectionFactory</attribute>
        <attribute name="FromName">QueueConnectionFactory</attribute>
    </mbean>
      

  4.   

    谢谢楼上热心的兄弟,我的描述不是很清楚,重新叙述一下吧:
    我想通过修改jboss server的配置文件在服务器上bind一个resource(string),以便能在代码中通过jndi查找并使用这个resource。要实现的效果,和下面的代码实现是一致的:
       
        javax.naming.InitialContext().bind("myJndi", "a-string");此时在其他地方我可以通过jndi获取到一个resource(下例中的string s):            Context iniCtx = new InitialContext();
                Object o= iniCtx.lookup("myJndi");
                String s=o.toString();//-----------------------------------------------------------------------------------
    问题尚未解决,请知情的兄弟多多帮忙。
    再次谢谢楼上几位热心的朋友。