FAQ What is the classpath of a plug-in?

From Eclipsepedia

Jump to: navigation, search

Developers coming from a more traditional Java programming environment are often confused by classpath issues in Eclipse. A typical Java application has a global namespace made up of the contents of the JARs on a single universal classpath. This classpath is typically specified either with a command line argument to the VM or by an operating system environment variable. In Eclipse, each plug-in has its own unique classpath. This classpath contains the following, in lookup order:

  • The OSGi parent class loader. All class loaders in OSGi have a common parent class loader. By default, this is set to be the Java boot class loader. The boot loader typically only knows about rt.jar, but the boot classpath can be augmented with a command line argument to the VM.
  • The exported libraries of all imported plug-ins. If imported plug-ins export their imports, you get access to their exported libraries, too. Plug-in libraries, imports, and exports are all specified in the plugin.xml file.
  • The declared libraries of the plug-in and all its fragments. Libraries are searched in the order they are specified in the manifest. Fragment libraries are added to the end of the classpath in an unspecified order.

In Eclipse 2.1, the libraries from the org.eclipse.core.boot and org.eclipse.core.runtime were also automatically added to every plug-in’s classpath. This is not true in 3.0; you now need to declare the runtime plug-in in your manifest’s requires section, as with any other plug-in.

Pragmatic Advice

Here are some suggestions if you have plug-in code that compiles (classes found) but fails at runtime with class not found. There are at least three different classpaths:

  1. compile time
  2. runtime
  3. source code at debug

There are at least four different places these are controlled:

  2. Preferences PDE Target Platform
  3. Project Right click Build Path Configure Build Path
  4. Launch Configuration.

Unless you know what you are doing, the first thing to do is make sure that you only use MANIFEST.MF. In particular the Configure Build Path has to be cleared out of anything you put in there because it is only seen at compile time.

In the MANIFEST.MF systematically try to use Dependencies->RequiredPlugins and avoid Runtime->Classpath for anything other than classes for your plugin. (The theoretical best solution is to use "ImportedPackages" but its not clear to me what this thing does in practice.)

If you still have trouble, go in to the source at the where you have the runtime problem and "Open Declaration" on the method or field. Then use the little double arrow thingy on Package Explorer to sync the package view to the method. That will tell you what lib/plugin is bound at compile time. Then you need to run the debugger to the line and figure out why that lib/plugin is not on the path.

See Also:

This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.