Steps for using Eclipse Plugin fragment

Source: Internet
Author: User

In the development of RCP or IDE, sometimes we need to take advantage of some third-party open source plug-in projects, but do not want to change their source code (to facilitate the subsequent synchronization upgrade and the project consistent), then fragment is a good choice.

Recently I have encountered such a situation, however, with their own understanding, has not been able to make the fragment effective (have to spit trough Eclipse plug-in development is really small, the data is very difficult to find), after a day more torture, gradually understand the use of fragment several key points, to share.

Share an English profile first (http://wiki.eclipse.org/Steps_to_use_Fragments_to_patch_a_plug-in)

If you do not follow the law, then you may wish to continue to look at my understanding and summary:

STEP1: Create Fragment

This is very simple, through the Eclipse's new wizard, follow the steps to create, the creation process needs to specify fragment ID, version and other information (with plugin surprisingly consistent), and most importantly, specify the fragment corresponding host plug-in, Select the button configuration from the wizard.

In this step, fragment created, then the key point, in order to ensure that the fragment in the configuration file (fragment.xml) and Java code can be loaded by the host, and overwrite the host corresponding content, need to do the following:

1) Open meta-inf/manifest. MF file, click on the Manifest.mf tab, add Eclipse-patchfragment:true configuration, as I understand, this configuration can declare the current fragment for fragment (nonsense), The host plugin loads the fragment at the same time, which ensures that the extension definition in the fragment takes effect.

2) Open the Runtime tab, click Classpath->new, add Library.jar and "." (Just follow the wizard by default), and move the Library.jar up to "." Before

3) switch to the Build tab, delete "." and save.

Step2:make Patch

In the host plug-in, find the class you want to modify, complete the copy to the Fragment source folder (SRC), the package path and class name must be consistent, and then do the want.

However, after starting, you will still find that the code you changed is not executed and the original host code is still executed because of the lack of the following important configuration.

STEP3: Configuring the host Plug-in

1) Open Host plugin (can be imported via Import->plug-ins and Fragment wizard with source project or project with source folder)

2) Open meta-inf/manifest. MF file, click on the Manifest.mf tab, add Eclipse-extensibleapi:true (this configuration guarantees that the fragment code will be loaded, but can be loaded into the following configuration)

3) Open the Runtime tab, click Classpath->new, add Library.jar and "." (Just follow the wizard by default), and move the Library.jar up to "." Before

4) Switch to the Build tab, delete "Library.jar." and save.

※3) and 4) correspond to STEP1 2) and 3, in general, the host plug-in is guaranteed to load the library's code logic in the same case as the package path class name, followed by loading the host's own code logic, And Library.jar point to the source code of fragment, so that the fragment logic to ensure that the first effective.

The development configuration for this fragment is complete. It is important to note that the host plugin has been changed when packaged to form the final product and needs to be re-exported as a plug-in (which minimizes host churn compared to other methods), rather than the original third-party plug-in.

And if you are a skilled, you will find all the operations, the final effect is only the configuration of the Manifest.mf file, familiar with this you can directly change the host plugin's. MF file without having to re-package the host

Memo: Path non-code files with the same name, such as whether other files other than plugin.xml can take effect in this manner, to be tested (may need to be branch-processed in the loaded code logic, like NLS operations)

Steps for using Eclipse Plugin fragment

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.