How the Eclipse plugin introduces a jar package

Source: Internet
Author: User

After two days, I finally found a solution. Originally the Eclipse plug-in project introduced outside the jar package cannot use the build path---->add external jars method.

Two concepts are described first: ClassLoader, OSGI

The ClassLoader (class loader), as the name implies, is a tool that the JVM uses to load classes. Of course, it is also a Java class, see Java.lang.ClassLoader. It maintains internal class name spaces, interrelationships (domains), and isolates them from external attacks.

Osgi,open Service Gateway Initiative is an open architecture with key features including hot-swappable, bundle-independent, and more. The current version of Eclipse is based on this architecture, and the main way for Eclipse to implement OSGi is by assigning a separate classloader to each bundle, Then use the configuration of the MANIFEST.MF file to maintain the relationships between these bundles.

Like a line of code:

Platform.getbundle (bundle_id)

This is the way to get the classloader of bundle_id, which calls the bundle (plug-in) in the same way that the class is called by reflection.

Business:

How do I refer to a jar package in a plugin? Some of the newly-developed Eclipse plugin developers often add the jar package they need to the project's running environment, although there is no problem when editing the Eclipse editor, but once the program is run, it is unavoidable that the class cannot be initialized or the class cannot be found.

This is because the classloader of each bundle is independent, and the jar package that is added when the project is run is not loaded into the classloader of this bundle, and of course this error occurs.

Both scenarios solve this problem (this article uses Eclipse 3.7):

1, if the use of a jar package is only within the plug-in, then you can select the Runtime tab in MANIFEST.MF, find the Classpath area,

Click the "ADD" button and the following dialog box appears:

Select the jar package you want to add here.

Attention! The Add wizard shows the files, folders only the content under this plugin, so you need to create a "Lib" folder, the need to place the jar under it (the folder named Lib is a conventional practice, such as unnecessary, do not unconventional).

2, if a jar package needs to be referenced by multiple plug-ins, scenario 1 becomes cumbersome. A common jar reference can be implemented using a jar-package-plug-in approach.

Shortcut keys CTRL + N Create a new "others" and select

Then follow the prompts to create a jar package plug-in. Rely on it where you need it.

-------------------------

3, although only listed two points, but in fact there is a way three. This is the combination of two points, first referencing the jar package in Classpath, and then opening these jar packages in the export package. Then in the required plug-in to rely on the former plug-in, you can. This makes the configuration relatively flexible.

Http://www.cnblogs.com/wangjiyuan/p/jar.html

How the Eclipse plugin introduces a jar package (GO)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.