intellij idea的插件开发小结


最近在做一个intellij idea的插件,作用是读取数据库的表及字段的信息和预先定义的模板来生成代码文件(实体,service,springmvc中的controller,freemark文件等等)。

查找了很多资料,发现intellij idea插件开发的资料不仅少而且很多文档过期了,看了下官网的下载资料,到版本8之后就没有发布插件开发的api和例子资料包。开发中遇到最好的开发文档是《IntelliJ IDEA Plugin Development》(此文档的链接:http://wenku.baidu.com/link?url=0wRKHIJA7PSE4OcQBx9nVw1tcLXJsF3SNQcVEvf_lPkqdB-YE0q7GKnX6iGdRpkcJkxqODjQja0nARMx8zwkDacUqOKFpI6V0_V_-kGpfk)基本概念和例子可以在这篇文档中很好地体现,在这里就不重复了。这里暂且记录下开发中遇到的几个印象深刻的问题(开发环境,intellij idea13):


1.配置信息的持久化

《IntelliJ IDEA Plugin Development》中的配置信息持久化方法已经过期了,而且api方式有很大问题,比如用默认的的持久化类DefaultJDOMExternalizer配置信息的属性的访问权限只能为public,因为底层用的是反射方式。应该改为如下的配置方式:

@State( name = "com.xlight.code.generator.component.DBSettingApplicationComponent",
        storages = {@Storage(file = "$APP_CONFIG$/cg.xml")})
//cg.xml默认地址 C:\Users\Administrator\.IntelliJIdea13\system\plugins-sandbox\config\options

public class DBSettingApplicationComponent implements ApplicationComponent,
        Configurable, PersistentStateComponent<DBSettingApplicationComponent> {
.....................其他代码在此处省略..................

 @Nullable
    @Override
    public void loadState(DBSettingApplicationComponent state) {
        XmlSerializerUtil.copyBean(state, this);
    }
    @Override
    public DBSettingApplicationComponent getState() {
        return this;
    }

}

在路径C:\Users\Administrator\.IntelliJIdea13\system\plugins-sandbox\config\options中可以找到持久化xml文件cg.xml


2.插件打包后插件资源文件读取失败问题

插件项目打包后生成了zip文件(zip内包含有class文件和资源文件的jar包),安装后发现资源文件不能正常读取,原因在于资源文件放在了jar文件里面,经常有可能造成和没有打包成jar的情况时不一样的结果。解决方法可以参考http://www.iteye.com/topic/483115





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章