关键词:
idea插件开发- hello world
1.本文环境
idea 版本=2021.2.2
java 版本=11
电脑=macbook m1
确认是否安装了下面插件:
2.新建插件项目
使用gradle创建
选择位置
新建成的项目结构:
SDK切换
新建后项目使用的jdk11. 保持不变也能运行,但最好切换到插件SDK
方法如下
然后默认,选择jdk11
再在project settions 中选择新加的sdk
build.gradle文件
使用阿里云仓库
plugins
id 'org.jetbrains.intellij' version '1.9.0'
id 'java'
group 'org.example'
version '1.0-SNAPSHOT'
repositories
maven
url 'https://maven.aliyun.com/repository/public/'
mavenLocal()
mavenCentral()
dependencies
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij
version = '2021.2.2'
plugins = ['com.intellij.java']
patchPluginXml
changeNotes = """
Add change notes here.<br>
<em>most HTML tags may be used</em>"""
test
useJUnitPlatform()
必须加上plugins = ['com.intellij.java']
不然启动会报找不到类。
刷新依赖
3.新建第一个action
动作配置
这样就有了第一个动作类
动作类中实现第一个hello world
package com.demo;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.PsiFile;
public class Action1 extends AnAction
@Override
public void actionPerformed(AnActionEvent e)
//获取当前在操作的工程上下文
Project project = e.getData(PlatformDataKeys.PROJECT);
//获取当前操作的类文件
PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
//获取当前类文件的路径
String classPath = psiFile.getVirtualFile().getPath();
String title = "Hello World!";
//显示对话框
Messages.showMessageDialog(project, classPath, title, Messages.getInformationIcon());
plugin.xml中会自动添加Action信息
<idea-plugin>
<id>org.example.ide-plugin-demo2</id>
<name>Plugin display name here</name>
<vendor email="support@yourcompany.com" url="http://www.yourcompany.com">YourCompany</vendor>
<description><![CDATA[
Enter short description for your plugin here.<br>
<em>most HTML tags may be used</em>
]]></description>
<!-- please see https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html
on how to target different products -->
<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.lang</depends>
<depends>com.intellij.modules.java</depends>
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
</extensions>
<actions>
<!-- Add your actions here -->
<action id="action001" class="com.demo.Action1" text="动作1" description="第一个测试动作">
<add-to-group group-id="GenerateGroup" anchor="first"/>
</action>
</actions>
</idea-plugin>
4.启动项目并验证插件
点启动按钮或runide都可以
运行后会重新运行一个ide
这个idea 里面默认就安装了我们开发的插件
新建或随便打开一个项目
然后验证插件是否可以用
类中鼠标右键,找到generate
找到我们自定义的动作
弹出了我们设置的弹出框
第一个插件,到此完成。
爬坑
若启动没问题,运行时报错
NoClassDefFoundError: com/intellij/psi/PsiJavaFile
有依赖,就是一直报找不到类。
报错是NoClassDefFoundError: com/intellij/psi/PsiJavaFile,找不到intellij平台的PsiJavaFile类。
这是一个intellij平台插件兼容性的问题。
笔者猜测IDEA 2020启动插件的时候,默认不再包含Java language PSI Model模块。
因此需要将模块依赖添加到插件的配置文件plugin.xml中,添加进去之后是这样的:
<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.lang</depends>
<depends>com.intellij.modules.java</depends>
1.antlr4helloworld基础开发与idea插件使用(代码片段)
1.ANTLR4helloworld基础开发与IDEA插件使用下一篇:2.antlr4开发获取源码无需antlr4任何安装,基于IDEA创建一个Java项目,开发antlr的helloworld,使用antlr插件测试规则。输入hello后,才算匹配,然后显示world内容。1.... 查看详情
scala安装和idea中开发(代码片段)
...da开发Scala1.在线下载Scala插件2.离线下载Scala插件3.验证五.HelloWorld入门程序1.新建Maven项目/模块2.默认下,maven不支持Scala的开发,需要引入Scala框架3.再main目录下,新建一个scala目录,然后添加为源目录4.建一个Scala的类5.编写HelloWor... 查看详情
史上最全idea插件开发入门实战(傻瓜式教程)(代码片段)
...实战文章目录idea插件开发入门实战前言一、书写第一个HelloWorld二、IDEA插件开发进阶1.基于java文件的规则校验2.基于XML文件规则的校验3.基于java文件的代码自动生成方法4.基于XML文件的读写方法5.XML跳转Java文件前言建议先看一遍... 查看详情
idea插件开发-helloworld
idea插件开发-helloworld1.本文环境2.新建插件项目build.gradle文件3.新建第一个action4.启动项目并验证插件1.本文环境idea版本=2021.2.2java版本=11电脑=macbook确认是否安装了下面插件:2.新建插件项目使用gradle创建选择位置新建成的项目结... 查看详情
实践idea插件开发(代码片段)
目录为什么开发idea插件?开发插件流程(最简单的使用场景)配置IntelliJPlatformPluginSDK创建一个插件项目启用PluginDevKit创建一个动作action打包插件安装插件 以前觉得开发idea的人真厉害啊,后来工作中用到各种插... 查看详情
idea插件开发(代码片段)
文章目录前言插件工程创建插件工程结构plugin.xmlPluginActionAction是什么创建Action注册Action快速创建Action运行插件打包插件安装插件PluginComponentsComponents类型创建Component获取Component实例持久化PropertiesComponentPersistentStateComponent注册持... 查看详情
idea插件开发(代码片段)
文章目录前言插件工程创建插件工程结构plugin.xmlPluginActionAction是什么创建Action注册Action快速创建Action运行插件打包插件安装插件PluginComponentsComponents类型创建Component获取Component实例持久化PropertiesComponentPersistentStateComponent注册持... 查看详情
第一课helloworld程序(代码片段)
接触一门编程语言都是从HelloWorld开始的。我们以Idea为开发工具,写一个JAVA版的HelloWorld。 1,启动idea,点击菜单File->New->Project 新建一个Java工程 2,右键点击src目录New->JavaClass在新建的文件中打开写入以... 查看详情
idea插件开发从0入门idea插件开发,idea插件开发教程,如何开发idea插件(代码片段)
idea插件介绍作为一枚程序员,平时最常用的ide就是IntelliJIDEA。平时会用到各种各样的插件,通过插件的使用,提高自己的开发效率。idea具有全局性,安装好插件后,对idea生效,所有的工程均能找到。idea... 查看详情
idea创建helloworld!职业生涯的第一行代码(代码片段)
...建工程,介绍Java里的最简单也是最经典的的入门程序HelloWorld。1)打开IDEA软件, 查看详情
idea插件开发---extensionpoints(代码片段)
通过在插件中定义扩展点,您可以允许其他插件扩展您的插件的功能。有两种类型的扩展点:接口扩展点允许其他插件使用代码扩展您的插件。当您定义接口扩展点时,您指定了一个接口,其他插件将提供实现该... 查看详情
idea插件开发(11)---插件配置文件(代码片段)
以下是一个示例插件配置文件。此示例展示并描述了可在plugin.xml文件中使用的所有元素。有关配置的更多信息,请参见第II部分的“操作”部分。和元素中允许使用有限的HTML元素。但是,包含HTML元素的内容必须被<![CDA... 查看详情
chrome插件编写之新版helloworld(代码片段)
...件之前,需要熟悉一下相应的chrome插件开发环境。从编写helloworld开始,参考阅读官方的教程,是一个不错的选择。这里主要是基于chrome的官方教程,稍稍做了一些修改和扩充,总结成了如下的几个部分。 在chrome中编写... 查看详情
idea插件开发(代码片段)
文章目录前言插件工程创建插件工程结构plugin.xmlPluginActionAction是什么创建Action注册Action快速创建Action运行插件打包插件安装插件PluginComponentsComponents类型创建Component获取Component实例持久化PropertiesComponentPersistentStateComponent注册持... 查看详情
2.antlr4开发(代码片段)
2.antlr4开发上一篇:1.ANTLR4helloworld基础开发与IDEA插件使用获取源码antlr4.7.21.通过MyHelloVisitor实现HelloVisitorpackagewang.xiaolei.lei;importorg.antlr.v4.runtime.tree.ErrorNode;importorg.antlr.v4.runtime.tree.Pars 查看详情
idea插件系列(33):restfultool插件——restful服务开发辅助工具集(代码片段)
1.插件介绍RestfulTool插件。一套Restful服务开发辅助工具集:提供了一个Servicestree的显示窗口双击URL直接跳转到对应的方法定义一个简单的http请求工具支持Spring体系(SpringMVC/SpringBoot)支持JAX-RS支持`Navigate->RequestService`搜... 查看详情
idea开发插件,插件依赖|文件路径转virtualfile遇坑随笔(代码片段)
...,但是每次运行起来的时候在菜单就找不到我配置的插件入口了<depends>com.intellij.modules.platform</depends><depends>Dart</depends>原 查看详情
idea开发插件,插件依赖|文件路径转virtualfile遇坑随笔(代码片段)
...,但是每次运行起来的时候在菜单就找不到我配置的插件入口了<depends>com.intellij.modules.platform</depends><depends>Dart</depends>原 查看详情