java 组件开发调试_如何在Eclipse中开发并调试自己的插件(或者说如何将自己的代码插件化)...

Setting up Eclipse to create and debug plugins for ImageJ

最近在做一个关于卫星遥感全链路仿真的项目,由于项目是基于ImageJ开发,而ImageJ提供了强大的插件机制,所以特来写一个东西说明如何将自己的代码转化为ImageJ的插件。

Alt-File –> New

Select the Java Project wizard and click Next

5a32d1f7f4ea0fec75a443418b0c9378.png

Project name: IJ. Check Create separate folders for sources and class files. Click Next

ba02523479e196d3f9147d7f9bec7c47.png

On the following panel, select Source tab and check if Default output folder is set to IJ/bin

72a64d7f1735722f55541b4c6a309e29.png

On the Libraries tab click on Add external JARs, browse to your Java SDK library folder , select tools.jar, click Ok and click on Finish to create the project.

(on my computer the Java SDK library folder is located at C:\Program Files\Java\jdk1.6.0_02\lib)

aacf158ca27f153e831d6c43bd6ed62f.png

Finally, get the latest copy of ij here, extract the zip

Copy the ij folder and its subfolders into the source folder

Copy the images, macros and plugins folder and only IJ_Props.txt to the IJ project root.

Click on F5 to tell Eclipse to refresh its Package list

d38bd70f3dfbed5df124af41cd388264.png

Create a new plugin (or import your previously developed plugins).

Alt-File –> New

Select the Java Project wizard and click Next

3a2a3b3f7401abaa6c6297f0ebe4f379.png

Give your plugin a name (don't forget to add an underscore if you want it to appear in the ImageJ menu!)

89b066ea891f918fa1141d9572943440.png

On the Source tab, check that the output folder is set TestPlugin_/bin

d140fdf5010769db64ad5e62bb97aec8.png

On the Project tab, click Add… and select your previously created IJ project containing the ImageJ source.

Click Finish

e0242deba5dc62da8a1fb17388773087.png

Create your Java plugin files. In our example, I created a sample TESTPlugin_.java with the following content:

importij.IJ;

importij.plugin.PlugIn;

publicclassTestPlugin_ implementsPlugIn {

publicvoidrun(Stringarg){

IJ.error("Hello world!");

}

}

37bd0f5390b84cf2b47e9a1ccd29a69d.png

Create a file called build.xml in the project root folder. A sample build.xml file follows, which you should adapt to your needs.

TESTPlugin_ build file

Building the .jar file.

36145fa2a2e570e1e94de0b1310709d5.png

In the Package Explorer, right click on the TESTPlugin_ project, click on Properties, select Builders, click New… and select Ant Builder

16bf90dc35f8ceeb6d21a2558a140877.png

In the Main Tab, click Browse workspace and select the build.xml from your TESTPlugin_ project.

90a12d5fb4c79226a2286a09e35074de.png

In the Targets tab, click Set Targets for both After clean and Auto build targets, and select both main and compress.

Click Ok twice to keep your changes.

8f8c1179a9961d8f066bd1e61787635f.png

Goto Run→ Debug Configurations and create a new Java Application Debug Configuration. Fill in IJ In the field Project, and ij.ImageJ in the field Main class.

a28f541575a401ff50011e959d2b66e1.png

Select the Source tab, then in the Source lookup path, Add→Add Java Project. Select the TestPlugin_ project. This step is crucial if you want to step into your plugin source during the debug phase. Apply the changes.

e33a3949aa6088c9f7e69e778b341221.png

If you select Debug, ImageJ will start and your TESTPlugin_ will show up in the Plugins menu…

Set breakpoints in plugins or in the ImageJ source, the debugger should break accordingly.

551245f96d202c3c353d0d29bdea3c69.png

后注:当然上文只是其中一种方法,也还有其他方法可以实现!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值