[Closed] Name java:comp is not bound in this Context (JNDI)

Pablo Beltran
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 25, 2014

Hi,

I get the following exception: Name java:comp is not bound in this Context while trying to get the JNDI context from a plugin:

InitialContext ic = new InitialContext();
Context env = (Context) ic.lookup("java:comp/env");

Any idea?

Thanks!

Pablo.

4 answers

1 accepted

0 votes
Answer accepted
Pablo Beltran
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 26, 2014

I found the solution. Binding the missing names resolves the problem.

Lai Dai April 29, 2015

Hi Pablo, What do you mean by binding the missing names? Can you give an example? Thanks

0 votes
Pablo Beltran
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 26, 2014

Hi zezeto, thanks for the link. I read all those links some days ago but I was unable to find any solution there as I do not want use JNDI to get datasources. I want to use JNDI to bind a string (object) in order to configure some 3rd party code expecting be configured through JNDI. Thanks.

0 votes
Pablo Beltran
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 26, 2014

This is very confusing...

According to the AMPS-737 issue jndi is supported for datasources since the AMPS 4.1 version:

I'm using AMPS:

<amps.version>4.2.9</amps.version>

Following the AMPS-737, there is an Atlassian's example on Bitbucket to configure a datasource from a plugin:

As expected, the jndi string is:

<jndi-datasource>
        <jndi-name>java:comp/env/jdbc/JiraDS</jndi-name>
</jndi-datasource>

It means the name java:com/env is already binded.

However, fron a plugin, the javaURLContextFactory class must be added as a dependency (it is not exported by the JIRA system plugin):

<dependency>
			<groupId>directory-naming</groupId>
			<artifactId>naming-java</artifactId>
			<version>0.8</version>
		</dependency>

in order to use the InitialContext class.

As the factory is provided by the plugin rather by the application contanier (Tomcat/Catalina), it might not be properly initialized as accordingly to the Apache's documentation, it requires some environment configuration:

This factory MUST be associated with the "java" URL prefix, which can be done by setting an environment variable named Context.URL_PKG_PREFIXES with its value including the org.apache.catalina.util.naming package name.

It is not the case. By debugging I saw that is properly itinialized and the InitialContext properties are:

java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory

and

java.naming.factory.url.pkgs=org.apache.catalina.util.naming

But when I'm try to get the java.com/env context (which is the same used by the JNDI datasources supported from the 4.1 version!), it is not bound:

Context env = (Context) ic.lookup("java:comp/env");

How is it possible?

Thanks!

Pablo

0 votes
Nadir MEZIANI
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 26, 2014

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events