Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Accessing ui libraries in a headless Eclipse application
icon5.gif  Accessing ui libraries in a headless Eclipse application [message #990122] Tue, 11 December 2012 00:22 Go to next message
Kivanc Muslu is currently offline Kivanc Muslu
Messages: 153
Registered: November 2010
Senior Member
Hi all,

Whenever I try to load (Eclipse tries to load the related plug-ins as they are needed) org.eclipse.ui or org.eclipse.jdt.ui (and variants, such as, org.eclipse.jdt.ui.text), my headless application gives the following error:
org/eclipse/jdt/ui/text/java/IInvocationContext
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
	at java.lang.Class.getDeclaredMethod(Class.java:1952)
	at java.io.ObjectStreamClass.getPrivateMethod(ObjectStreamClass.java:1411)
	at java.io.ObjectStreamClass.access$1700(ObjectStreamClass.java:69)
	at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:481)
	at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:455)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:455)
	at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:352)
	at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:589)
	at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1601)
	at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
	at com.kivancmuslu.www.network.NetworkReader.readUntilShutdown(NetworkReader.java:26)
	at com.kivancmuslu.www.network.NetworkThread.run(NetworkThread.java:51)
	at java.lang.Thread.run(Thread.java:722)
An error occurred while automatically activating bundle org.eclipse.jdt.ui (174).
	at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:122)
	at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:469)
	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
	at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
	at org.eclipse.osgi.internal.loader.SingleSourcePackage.loadClass(SingleSourcePackage.java:35)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
	at java.lang.Class.getDeclaredMethod(Class.java:1952)
	at java.io.ObjectStreamClass.getPrivateMethod(ObjectStreamClass.java:1411)
	at java.io.ObjectStreamClass.access$1700(ObjectStreamClass.java:69)
	at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:481)
	at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:455)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:455)
	at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:352)
	at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:589)
	at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1601)
	at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
	at com.kivancmuslu.www.network.NetworkReader.readUntilShutdown(NetworkReader.java:26)
	at com.kivancmuslu.www.network.NetworkThread.run(NetworkThread.java:51)
	at java.lang.Thread.run(Thread.java:722)
Exception in org.eclipse.jdt.internal.ui.JavaPlugin.start() of bundle org.eclipse.jdt.ui.
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
	at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
	at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:263)
	at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
	at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:469)
	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
	at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
	at org.eclipse.osgi.internal.loader.SingleSourcePackage.loadClass(SingleSourcePackage.java:35)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
	at java.lang.Class.getDeclaredMethod(Class.java:1952)
	at java.io.ObjectStreamClass.getPrivateMethod(ObjectStreamClass.java:1411)
	at java.io.ObjectStreamClass.access$1700(ObjectStreamClass.java:69)
	at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:481)
	at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:455)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:455)
	at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:352)
	at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:589)
	at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1601)
	at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
	at com.kivancmuslu.www.network.NetworkReader.readUntilShutdown(NetworkReader.java:26)
	at com.kivancmuslu.www.network.NetworkThread.run(NetworkThread.java:51)
	at java.lang.Thread.run(Thread.java:722)
null argument:
	at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:85)
	at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:73)
	at org.eclipse.jface.resource.FontRegistry.<init>(FontRegistry.java:283)
	at org.eclipse.jface.resource.FontRegistry.<init>(FontRegistry.java:308)
	at org.eclipse.jface.resource.JFaceResources.getFontRegistry(JFaceResources.java:342)
	at org.eclipse.jdt.internal.ui.JavaPlugin.ensurePreferenceStoreBackwardsCompatibility(JavaPlugin.java:448)
	at org.eclipse.jdt.internal.ui.JavaPlugin.start(JavaPlugin.java:373)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
	at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
	at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
	at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
	at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:440)
	at org.eclipse.osgi.internal.loader.BundleLoader.setLazyTrigger(BundleLoader.java:263)
	at org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
	at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:469)
	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:216)
	at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:395)
	at org.eclipse.osgi.internal.loader.SingleSourcePackage.loadClass(SingleSourcePackage.java:35)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
	at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
	at java.lang.Class.getDeclaredMethod(Class.java:1952)
	at java.io.ObjectStreamClass.getPrivateMethod(ObjectStreamClass.java:1411)
	at java.io.ObjectStreamClass.access$1700(ObjectStreamClass.java:69)
	at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:481)
	at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:455)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.io.ObjectStreamClass.<init>(ObjectStreamClass.java:455)
	at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:352)
	at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:589)
	at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1601)
	at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
	at com.kivancmuslu.www.network.NetworkReader.readUntilShutdown(NetworkReader.java:26)
	at com.kivancmuslu.www.network.NetworkThread.run(NetworkThread.java:51)
	at java.lang.Thread.run(Thread.java:722)


I believe that this is due to the fact that I am trying to run this code in a headless Eclipse, which isn't supposed to call UI elements. However, I have to call these functions (from UI libraries), so I guess my question is:

1- Can I load UI libraries in a headless Eclipse without getting the above error?
or
2- Is there another way to run an Eclipse application (i.e., implements IApplication) so that it can access to UI library code without getting an error? (By the way, I tried running the application without --nosplash flag. It did not work)

Thank you,

[Updated on: Tue, 11 December 2012 00:23]

Report message to a moderator

Re: Accessing ui libraries in a headless Eclipse application [message #1064860 is a reply to message #990122] Fri, 21 June 2013 12:28 Go to previous message
Kivanc Muslu is currently offline Kivanc Muslu
Messages: 153
Registered: November 2010
Senior Member
This is not a complete solution and a quite hacky one, however for the moment, to access some of the UI libraries (that does not have extra checks), you can try the following:

1. Create a display: it is free to do that and you don't need a UI to do it:
PlatformUI.createDisplay();


2. Load some known UI libraries:
loadPlugins("org.eclipse.ui", 
                    "org.eclipse.jdt.ui", 
                    "org.eclipse.ui.ide", 
                    "org.eclipse.ui.workbench.texteditor");

// where ...

    private void loadPlugins(String... pluginIDs)
    {
        ArrayList<URL> urls = new ArrayList<>();
        for (String pluginID: pluginIDs)
        {
            @SuppressWarnings("null") @NonNull String safeID = pluginID;
            URL url = getPluginURL(safeID);
            if (url != null)
                urls.add(url);
        }

        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
        @SuppressWarnings("resource") URLClassLoader classLoader =
            new URLClassLoader(urls.toArray(new URL[urls.size()]), currentClassLoader);
        Thread.currentThread().setContextClassLoader(classLoader);
    }

    private @Nullable URL getPluginURL(String pluginID)
    {
        Bundle bundle = Platform.getBundle(pluginID);
        try
        {
            File file = FileLocator.getBundleFile(bundle);
            URL result = file.toURI().toURL();
            return result;
        }
        catch (IOException e)
        {}
        return null;
    }


3. Activate JavaPlugin (must be done by the main thread in some OSes):
JavaPlugin.getDefault();
Previous Topic:[SOLVED] Preference Page for my Plug-in does not Load
Next Topic:Set up Eclipse development environment
Goto Forum:
  


Current Time: Sat Oct 25 16:07:14 GMT 2014

Powered by FUDForum. Page generated in 0.10309 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software