-
1. Re: javax.naming.NoInitialContextException: Can't find prope
waynebaylor Jan 5, 2008 1:50 AM (in response to joepareti)just for kicks, you could pass InitialContext a Hashtable with your jndi.properties hardcoded. if that works, then you know it's something wrong with your classpath.
ps. you lookup string looks funny, by default it's "[ear-name/]bean-name/local" -
2. Re: javax.naming.NoInitialContextException: Can't find prope
jaikiran Jan 7, 2008 6:15 AM (in response to joepareti)As waynebaylor mentioned, the most likely reason is that the jndi.properties file is not being found in the classpath. Try out waynebaylor's suggestion. Furthermore, which version and implementation of Java are you using? When you start JBoss, it prints out the JDK information. I use JDK 5 from Sun and see this output when the server is starting:
16:37:22,464 INFO [ServerInfo] Java version: 1.5.0_07,Sun Microsystems Inc. 16:37:22,480 INFO [ServerInfo] Java VM: Java HotSpot(TM) Server VM 1.5.0_07-b03,Sun Microsystems Inc. 16:37:22,480 INFO [ServerInfo] OS-System: Windows 2003 5.2,x86
What do you see on your system?
Also, you mention that your jndi.properties contains:java.naming.factory.initial=org.jnp.interfaces.Nam ingContextFactory
I see a space between letters in "NamingContextFactory". Is this a typo while posting in the forum or is this the actual content in your jndi.properties file? -
3. Re: javax.naming.NoInitialContextException: Can't find prope
joepareti May 2, 2008 5:17 AM (in response to joepareti)After a long time I am revisiting this topic and even though I tried to implement your advise the very same error message stays:
javax.naming.NoInitialContextException: Can't find property: java.naming.factory.initial
Below are the details on what I did. TIA for any further help.
SOURCE CODE MODIFICATIONS
package za.co.solms.finance.calculators;
import javax.naming.Context;
import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import swingwt.awt.*;
import java.text.*;
import java.util.*;
import swingwtx.swing.*;
import swingwt.awt.event.*;
public class LoanCalculatorClient extends JFrame
{
public LoanCalculatorClient()
{
setTitle("Solms Training Loan Calculator");
java.util.Hashtable properties = new java.util.Hashtable();
properties.put(Context.PROVIDER_URL,"localhost:1099");
properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.rmi.security.manager", "yes");
/*env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming.client:org.jnp.interfaces");*/
/* this is default env.put(jnp.socketFactory,"org.jnp.interfaces.TimedSocketFactory"); */
/* Context initialContext = new InitialContext(env); */
javax.naming.Context context = new javax.naming.InitialContext(properties);
calculatorPanel = new LoanCalculatorPanel();
getContentPane().add(calculatorPanel);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent event)
{
calculatorPanel.destroy();
System.exit(0);
}
});
pack();
}
public static void main(String[] args)
{
new LoanCalculatorClient().show();
}
private LoanCalculatorPanel calculatorPanel;
}
=======
public void connect()
{
try
{
InitialContext jndiContext = new InitialContext();
System.out.println("Now looking up session bean " + jndiName + " ...");
java.util.Hashtable properties = new java.util.Hashtable();
properties.put(Context.PROVIDER_URL,"localhost:1099");
properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.rmi.security.manager", "yes");
javax.naming.Context context = new javax.naming.InitialContext(properties);
Object beanHomeRef
= jndiContext.lookup(jndiName);
System.out.println("got it");
LoanCalculatorHome home =
(LoanCalculatorHome)PortableRemoteObject.narrow
(beanHomeRef, LoanCalculatorHome.class);
loanCalculator = home.create();
}
ERRORS IN THE LOG FILE FROM BUILDING THE CLIENT JAR
/usr/local/samba/tmp/jboss/jboss_demo_solms/src/client/application/LoanCalculatorClient.java:17: error: Undefined variable or class name: `java.naming.factory.initial'.
[javac] env.put(java.naming.factory.initial,"org.jnp.interfaces.NamingContextFactory");
[javac] ^
[javac]
This has been fixed by using:
properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
in lieu of:
properties.put(java.naming.factory.initial,"org.jnp.interfaces.NamingContextFactory");
This may be a coincidence, but the client run-time error also refers to "java.naming.factory.initial" ; so I am starting to suspect a more fundamental problem with java.
ALTERNATIVE WAYS TO ACCESS THE JNDI SERVICE?
Because I think the following java statement causes the exception:
Object beanHomeRef
= jndiContext.lookup(jndiName);
I am wondering if one could use instead something like:
Object beanHomeRef
= jndiContext.lookup("java:/path");
Or
Java.lang.Object ejbHome =
= initialContext.lookup("ava:/path");
WARNINGS IN THE LOG FILE FROM BUILDING THE CLIENT JAR
I don't know how serious the following are:
[javac] Using gcj compiler
dropping /usr/local/samba/tmp/jboss/jboss_demo_solms/${classpath} from path as it doesn't exist
and
Property ${classpath} has not been set
- is classpath case sensitive?
- I know from a previous experience that classpath was fixed by just listing jar files; in this case it does indeed contain jar files AND regular directories ??? -
4. Re: javax.naming.NoInitialContextException: Can't find prope
kahzoo May 6, 2008 8:44 PM (in response to joepareti)InitialContext jndiContext = new InitialContext(); System.out.println("Now looking up session bean " + jndiName + " ..."); java.util.Hashtable properties = new java.util.Hashtable(); properties.put(Context.PROVIDER_URL,"localhost:1099"); properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory"); properties.put("java.naming.rmi.security.manager", "yes"); javax.naming.Context context = new javax.naming.InitialContext(properties); Object beanHomeRef = jndiContext.lookup(jndiName);
I wonder if the the last line really should be:Object beanHomeRef = context.lookup(jndiName);
because when you construct jndiConext, you're not passing the properties as argument:InitialContext jndiContext = new InitialContext();
rather you do that for context,javax.naming.Context context = new javax.naming.InitialContext(properties);
-
5. Re: javax.naming.NoInitialContextException: Can't find prope
joepareti May 16, 2008 5:22 AM (in response to joepareti)I have made the following code change (see statement in bold), because the expression involving = new InitialContext() should in my opinion follow the proerties settings, however that didn't solve the problem.
kahzoo-san; do you mean the statement should be:Object beanHomeRef = context.lookup();
or should I use ?InitialContext=jndiContext = new InitialContext(properties);
=======
public void connect() { try { System.out.println("Now looking up session bean " + jndiName + " ..."); java.util.Hashtable properties = new java.util.Hashtable(); properties.put(Context.PROVIDER_URL,"localhost:1099"); properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory"); properties.put("java.naming.rmi.security.manager", "yes"); javax.naming.Context context = new javax.naming.InitialContext(properties); InitialContext jndiContext = new InitialContext(); Object beanHomeRef = jndiContext.lookup(jndiName); System.out.println("got it"); LoanCalculatorHome home = (LoanCalculatorHome)PortableRemoteObject.narrow (beanHomeRef, LoanCalculatorHome.class); loanCalculator = home.create(); }
-
6. Re: javax.naming.NoInitialContextException: Can't find prope
kahzoo May 17, 2008 7:52 AM (in response to joepareti)Sorry if my previous post was not clear enough.
I suggested to change the code as follows:public void connect() { try { System.out.println("Now looking up session bean " + jndiName + " ..."); java.util.Hashtable properties = new java.util.Hashtable(); properties.put(Context.PROVIDER_URL,"localhost:1099"); properties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory"); properties.put("java.naming.rmi.security.manager", "yes"); javax.naming.Context context = new javax.naming.InitialContext(properties); Object beanHomeRef = context.lookup(jndiName); System.out.println("got it"); LoanCalculatorHome home = (LoanCalculatorHome)PortableRemoteObject.narrow (beanHomeRef, LoanCalculatorHome.class); loanCalculator = home.create(); }
-
7. Re: javax.naming.NoInitialContextException: Can't find prope
joepareti May 17, 2008 8:59 AM (in response to joepareti)thanks Kazuhisa-san, I have not yet tried your latest suggestion, but I'd like to point out some strange messages from Jboss upon start up (via executing run.sh):
09:32:17,947 WARN [ServiceController] Problem starting service jboss:service=NamingBeanImpl javax.naming.NamingException: Failed to find j2ee.clientName in jndi env at org.jboss.naming.client.java.javaURLContextFactory.getObjectInstance(javaURLContextFactory.java:81) ... 09:32:31,310 ERROR [UUIDKeyGeneratorFactoryService] Caught exception during startService() javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 and discovery failed with error: javax.naming.CommunicationException: No such device [Root exception is java.net.SocketException: No such device] [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost:1099 [Root exception is java.net.ConnectException: Connection refused]]] at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1414) at org.jnp.interfaces.NamingContext.rebind(NamingContext.java:484) at org.jnp.interfaces.NamingContext.rebind(NamingContext.java:477) ...