Exceptionjavax.naming.NoInitialContextException: Need to specify class name in...
When i try to run my application, i get the error message Exceptionjavax.naming.NoInitialContextException: Need to specify class name in environment or system property,, or as an applet parameter, or in an application resource file: java.naming.factory.initial.
The line that throws the exception is Object ref = ctx.lookup("demo.CalculatorRemote");
Under project properties - Run i have VM Options set to -Djava.security.auth.login.config=C:/glassfishv3/glassfish/lib/appclient/appclientlogin.conf
/ Initial environment with various propertiesHashtable env = new Hashtable();env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.FSContextFactory");// Call the constructorContext ctx = new InitialContext(env);
Mnrz, when trying with your first code with env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.FSContextFactory"); i get the exception: Exceptionjava.security.AcessControlException: access denied (java.util.PropertuPermission user.dir read) exception thrown at ctx = new InitialContext(env);.
When adding env.put(Context.PROVIDER_URL, "localhost:1099"); from your link i get a exceptionjavax.naming.invalidnameexception: localhost: 1099 [root exception is java.netMalformedURLException: unknown protoctocol: localhost
a_b i don't understand what i should set as my lookup params, but i appreciate that you are taking your time to assist me. I just started learning this.
Well, I just wanted to show you the door, the second link I posted is telling the whole story about how to init the context.
Anyway, as an example look at following snippet code, you need to know the port for ORB in Glassfish it is usually 3700 but it depends on application server you are using.
Also if you are going to use InitialContxt as remote call you have to place ip address of the server instead of "localhost" and "127.0.0.1"
Right, i read trough the document you posted, experimented a bit but did not get anywhere. Anything i try seem to throw an exception at InitialContext. Trying the example you give now give the error i posted in the code window below. "java.lang.ClassNotFoundException: org.glassfish.internal.api.Globals" I assume i need to add some class to my project for this to work, but how do i figure out what class from the information given?
Java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.sun.javaws.Launcher.executeApplication(Launcher.java:1799) at com.sun.javaws.Launcher.executeMainClass(Launcher.java:1745) at com.sun.javaws.Launcher.doLaunchApp(Launcher.java:1507) at com.sun.javaws.Launcher.run(Launcher.java:129) at java.lang.Thread.run(Thread.java:619)Caused by: java.lang.NoClassDefFoundError: org/glassfish/internal/api/Globals at com.sun.enterprise.naming.impl.SerialInitContextFactory.<init>(SerialInitContextFactory.java:74) at com.sun.enterprise.naming.SerialInitContextFactory.<init>(SerialInitContextFactory.java:58) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) at javax.naming.InitialContext.init(InitialContext.java:223) at javax.naming.InitialContext.<init>(InitialContext.java:197) at programmaticlogintest.Main.main(Main.java:42) ... 9 moreCaused by: java.lang.ClassNotFoundException: org.glassfish.internal.api.Globals at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at com.sun.jnlp.JNLPClassLoader.findClass(JNLPClassLoader.java:332) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ... 22 more
Yes. Which application server your trying to log in remotely? The example I posted is for Sun Glassfish App server, if yours is the same, you need to add some jar files to your library. These Jar files are in application server lib folder or something like that
I am not sure about the name of jar files, but I think their names contains "client" try to find them and add to your classpath
0
endasilAuthor Commented:
I have added every jar file from the glassfish directory with a name containing the word "client" but still get the same error. I added a list of all the libs that i have added to the project.
Thank you for the suggestion, but sadly they are both added added and the problem remains.
Can't understand that it should be so hard to create a simple stand alone application communicating with a EJB...
0
endasilAuthor Commented:
Some more info that could be of use.
I am using glassfish 3.01, jdk 1.6.0.21 and netbeans 6.9.1 if there are any relevante differences between the version your using and i'm using when developing.
The error message only occurs in ctx = new InitialContext(env); if i have the glassfish-naming.jar added to the project. It will occur regardless if i have InitialContext(); or InitialContext(env);
If i do not have glassfish-naming.jar added to the project, InitialContext() will pass without error. Then it will throw the .NoInitialContextException exception at ctx.lookup("demo.CalculatorRemote");
If i do not have glassfish-naming.jar it will complain about not finding SerialInitContextFactory (since it is located in glassfish-naming.jar)
I am very grateful and impressed that you have not given up and keep trying to solve the problem.
Ok so go to above link it is all about glassfish... hope it helps
0
endasilAuthor Commented:
Yes i read that link tried it before i attempted the standalone client example. just like the standalone example it suggest that i should use InitialContext() without passing parameters. Doing that will cause the NoInitialContextException when trying to do a lookup (regardless if i do ctx.lookup("java:global/Calculator/Login-ejb") orctx.lookup("demo.CalculatorRemote") ).
According to the responses here NoInitialContextException is caused by not passing in anything in InitialContext(), that i am explicitly told not to do in the documentation. And it takes me back to step 1.
This is really strange! First why you didn't add gf-client.jar? please add it as well
as last idea, I am not sure but It might be that it needs JAXB jar files, can you please after testing with gf-client.jar, search for JAXB jar files and add them to your classpath.
Also make sure your added jar files are loaded by JVM. I means copying is not enough you need to add new files in your IDE (Netbeans)
one more thing to do is that, all the jar files can be opened with ZIP softwares, if you have WinRAR, it has a facility to search for a specific file within all zip files... so you can search the missing class, "Globals.class", go to folder that all your jar files are placed and open one of them wih winRar or something and then using WinRAR go one level up and then press a find button (or anything like that) and search for file named Globals.class if it finds that file it will show you the name of jar file as well, this means you have it but it is not loaded so you need to tell your IDE to load it
also if you find it check the path, it should be the same path as the exception says:
org/glassfish/internal/api/
if you didn't find it then try to search under the glassfish installed folder, if you didn't find it again, try downloading the JAXB jar files, if it fails again, I suggest your go to Sun's forum (which is now Oracle of course :) ) and post a thread over
Please inform us if you managed to resolve the issue or not
Thanks
0
endasilAuthor Commented:
I was not able to solve it on glassfish3. Today i tried uninstalling glassfish3 and install glassfish 2 instead, and with that have no problem making this program work. So it seem to be something that is different with glassfish3...
Good. Maybe the Oracle tries to embed their database into glassfish :) (just kidding)
0
endasilAuthor Commented:
I did not find a way to solve my issues on glassfish 3, had to abandon that platform and instead work on glassfish 2 and got it working there. Even if the issue was not solved completely Mnrz provided me with alot of valuable informaiton and deserv some points for that.
0
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
http://www.developer.com/java/data/article.php/10933_2215571_4/Locating-Resources-Using-JNDI-Java-Naming-and-Directory-Interface.htm