Project Builders and Natures In Eclipse

本文介绍Eclipse中项目性质(project nature)的概念及其用途,包括如何定义项目性质及关联的构建器。此外,还涉及如何通过插件扩展点来为项目性质添加图标,并使用装饰器来增强工作台视图中的资源显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Project natures allow a plug-in to tag a project as a specific kind of project. For example, the Java development tools (JDT) use a "Java nature" to add Java-specific behavior to projects.  Project natures are defined by plug-ins, and are typically added or removed per-project when the user performs some action defined by the plug-in.

 

A project can have more than one nature.  However, when you define a project nature, you can define special constraints for the nature:

one-of-nature - specifies that the nature is one of a named set.  Natures in a set are mutually exclusive; that is, only one nature belonging to the set can exist for a project.

requires-nature - specifies that the nature depends on another nature and can only be added to a project that already has the required nature.

To implement your own nature, you need to define an extension and supply a class which implements IProjectNature.

 

The workspace supports the notion of an incremental project builder (or "builder" for short"). The job of a builder is to process a set of resource changes (supplied as a resource delta). For example, a Java builder would recompile changed Java files and produce new class files.

Builders are confgured on a per-project basis and run automatically when resources within their project are changed. As such, builders should be fast and scale with respect to the amount of change rather than the number of resources in the project. This typically implies that builders are able to incrementally update their "built state".

 

Eclipse Article:

Project Builders and Natures

 

Plugin.xml configuration:

   <extension 
   	id="mynature" 
   	name="My Nature" 
   	point="org.eclipse.core.resources.natures"> 
      <runtime> 
         <run class="com.xyz.natures.MyNature"/> 
      </runtime> 
      <builder id="com.xyz.myplugin.mybuilder"/> 
   </extension> 
   <extension 
   	id="mybuilder" 
   	name="My Builder" 
   	point="org.eclipse.core.resources.builders"> 
      <builder hasNature="true"> 
         <run class="com.xyz.builders.MyBuilder"/>
      </builder> 
   </extension> 
  

Append Icon to new project type on project navigator:

<extension
	point="org.eclipse.ui.ide.projectNatureImages">
	<image icon="icons/javafx_icon.png"
		id="com.sun.javafx.eclipse.core.natureImage"
		natureId="com.sun.javafx.eclipse.core.javafxNature">
	</image>
</extension>

This extension point is used to associate an image with a project nature. The supplied image is used to form a composite image consisting of the standard project image combined with the image of its nature. The supplied image is drawn over the top right corner of the base image. 

 

Howto create a new project nature in Eclipse

 

Decorators

Your plug-in can use decorators to annotate the images for resources and other objects that appear in the workbench views.  Decorators are useful when your plug-in adds functionality for existing resource types.  Many of the standard workbench views participate in showing decorations.  

Package explorer view with PDE decorators

 

Decorators Guide

http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_decorators.html

 

Dextension point

http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_decorators.html

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值