Bug 8907 - ClassLoader's don't handle CORBA or EJB lookups within a plug-in
Summary: ClassLoader's don't handle CORBA or EJB lookups within a plug-in
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 1.0   Edit
Hardware: PC Windows NT
: P1 blocker (vote)
Target Milestone: ---   Edit
Assignee: DJ Houghton CLA
QA Contact:
URL:
Whiteboard:
Keywords: readme
: 21299 40975 49249 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-02-01 00:29 EST by Jason Weiss CLA
Modified: 2003-12-23 08:42 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Weiss CLA 2002-02-01 00:29:29 EST
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)
Comment 1 John Arthorne CLA 2002-02-01 17:31:52 EST
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.
Comment 2 Jason Weiss CLA 2002-02-06 11:29:43 EST
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
Comment 3 Igor Fedorenko CLA 2002-02-28 12:42:28 EST
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.
Comment 4 John Wiegand CLA 2002-03-04 18:00:45 EST
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.
Comment 5 DJ Houghton CLA 2002-05-31 09:05:10 EDT
John has provided a work-around.
Include in README or ISV doc.
Comment 6 John Wiegand CLA 2002-11-22 16:23:17 EST
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. 
Comment 7 Rafael Chaves CLA 2003-07-31 13:59:54 EDT
*** Bug 40975 has been marked as a duplicate of this bug. ***
Comment 8 Rafael Chaves CLA 2003-10-01 12:36:58 EDT
*** Bug 21299 has been marked as a duplicate of this bug. ***
Comment 9 Mitchell Cope CLA 2003-12-23 08:42:30 EST
*** Bug 49249 has been marked as a duplicate of this bug. ***