Community
Participate
Working Groups
Trying to connect to an application server from within Eclipse. Tried utilizing both CORBA and EJB approaches. At first, I thought that Eclipse wasn't finding the client .jars, so I extracted everything to a common directory and built a single plug-in .jar. Still received the following exception. With CORBA lookups, the result was similar; unable to create an instance of com.sybase.CORBA.ORB. Possibly it has something to do with the Factory patterns utilized by both CORBA and EJB, where the name of the ORB / Factory class is passed in as a String. Boot URL: jar:file:D:/eclipse/plugins/org.eclipse.core.boot/boot.jar!/ Install URL: file:D:/eclipse/ Debug-Options: file:D:/eclipse/.options javax.naming.NoInitialContextException: Cannot instantiate class: com.sybase.ejb.InitialContextFacto ry. Root exception is java.lang.ClassNotFoundException: com.sybase.ejb.InitialContextFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:297) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286) at java.lang.ClassLoader.loadClass(ClassLoader.java:253) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:195) at com.sun.naming.internal.VersionHelper12.loadClass (VersionHelper12.java:45) at javax.naming.spi.NamingManager.getInitialContext (NamingManager.java:655) at javax.naming.InitialContext.getDefaultInitCtx (InitialContext.java:246) at javax.naming.InitialContext.init(InitialContext.java:222) at javax.naming.InitialContext.<init>(InitialContext.java:198) at com.sybase.alphabet.easerver.view.EASRepository.getInitialContext (com/sybase/alphabet/eas erver/view/EASRepository.java:24) at com.sybase.alphabet.easerver.view.EASRepository.connectEAServer (com/sybase/alphabet/easer ver/view/EASRepository.java:49) at com.sybase.alphabet.easerver.view.RepositoryView$1.run (com/sybase/alphabet/easerver/view/ RepositoryView.java:53) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection (ActionContributionI tem.java:407) at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent (ActionContributionItem. java:361) at org.eclipse.jface.action.ActionContributionItem.access$0 (ActionContributionItem.java:352) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent (ActionContribu tionItem.java:47) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:51) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:634) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1282) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1092) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:673) at org.eclipse.ui.internal.Workbench.run(Workbench.java:656) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:815) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:285) at java.lang.reflect.Method.invoke(Native Method) at org.eclipse.core.launcher.Main.basicRun(Main.java:151) at org.eclipse.core.launcher.Main.run(Main.java:433) at org.eclipse.core.launcher.Main.main(Main.java:306)
By any chance are you running Eclipse with a different security policy set? That is, are you starting up with Eclipse with -Djava.security.manager or -Djava.security.policy=... specified? This can affect what classes a URLClassLoader has permission to load.
I have not knowingly changed any security policy. In fact, here is the batch file (running on Windows) used to start eclipse: ============================= @echo off echo Setting up the Eclipse environment... SET JAVA_HOME=D:\jdk13 SET J2EE_HOME=d:\j2ee1_3 SET PATH=d:\eclipse;%JAVA_HOME%\bin;%J2EE_HOME%\bin;%SYSTEMROOT%;%SYSTEMROOT% \system32;. REM ************** REM * Environment Variables in Use REM ************** SET CLASSPATH=. echo Launching Eclipse Now... eclipse.exe -consolelog -debug
I had same problem with ant plugin and I was able to trace it down. Following two code snippets show the problem ==> this one works fine in plugin Object o; o = new my.test.pkg.TestClass(); o = Class.forName("my.test.pkg.TestClass").newInstance(); ==> this one throws java.lang.ClassNotFoundException: my.test.pkg.TestClass ClassLoader cl = Thread.currentThread().getContextClassLoader(); o = cl.loadClass("my.test.pkg.TestClass").newInstance(); I’ve checked that com.sun.naming.internal.VersionHelper12#loadClass(String) uses context class loader, so does sun’s implementation of Trax API. Hope this helps. -- Sincerely, Igor Fedorenko PS: this behaviour was observed in Eclipse 2.0 build 20020226.
Try the following: 1. Create a thread in which to run your code. 2. send yourThread.setContextClassLoader(yourClassLoader); // you can find your classloader by grabbing a class it loaded (YourPluginClass.class.getClassLoader()) 3. run your code in the created thread. If you set the context class loader for the current thread, you are competing with other users of the thread (all of eclipse) so the results will be unpredictable.
John has provided a work-around. Include in README or ISV doc.
RE my comment "If you set the context class loader for the current thread, you are competing with other users of the thread (all of eclipse) so the results will be unpredictable.": In practice this will not be a problem, provided you reset the context class loader back to its original value when your use in the current thread is complete.
*** Bug 40975 has been marked as a duplicate of this bug. ***
*** Bug 21299 has been marked as a duplicate of this bug. ***
*** Bug 49249 has been marked as a duplicate of this bug. ***