关于插件:confluence宏插件开发03Hello-World宏开发

通过后面的两篇文单的介绍,咱们曾经实现了开发环境的筹备和根本工程的创立。在这个根底上咱们来写一个HelloWorld 宏。

HelloWorld宏开发

步骤一,用Idea关上工程

应用Idea的时候有一个注意事项,就是要批改maven的 setting.xml文件。因为confluence应用的本人的服务器maven.atlassian.com来下载maven依赖。

  1. 点击Idea左上角的File菜单
  2. 关上Settings…
  3. 找到 Build, Execution, Deployment, 点开 Build Tools, 抉择 Maven
  4. 批改 User settings file的配置,点击左边的 override, 就能够写入值了。 能够通过 atlas-version命令来查看SDK的装置目录,咱们应用SDK目录下的 apache-maven-3.5.4\conf\setting.xml 配置文件
  5. 在Idea里更新maven的配置,查看是否maven依赖都能失常加载。第一次加载maven依赖的时候会比拟耗时间。

步骤二,批改配置文件

  1. 关上 src\main\resources\atlassian-plugin.xml 文件
  2. 在 </web-resource>前面退出,以下代码:
<xhtml-macro name="helloworld" class="com.example.Helloworld" key='helloworld-macro'>
        <description key="helloworld.macro.desc"/>
        <category name="formatting"/>
        <parameters/>
    </xhtml-macro>
  • 留神,xhtml-macro 和 web-resource 是同级节点。
  1. 关上 src\main\resources\myConfluenceMacro.properties 文件,退出helloworld.macro.desc 配置项
helloworld.macro.desc=Hello World

步骤三,插入Java代码

  1. 创立Helloworld类,写入以下代码
package com.example;

import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
import java.util.Map;

public class Helloworld implements Macro {
    @Override
    public String execute(Map<String, String> map, String s, ConversionContext conversionContext)
            throws MacroExecutionException {
        return "<h1>Hello World</h1>";
    }
    @Override
    public BodyType getBodyType() {
        return BodyType.NONE;
    }
    @Override
    public OutputType getOutputType() {
        return OutputType.BLOCK;
    }
}

步骤四,编译及成果查看

  1. 在命令行里运行 atlas-mvn package 命令,从新打包
atlas-mvn package
  1. 打包胜利后,会输入相似以下的信息:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.916 s
[INFO] Finished at: 2021-03-01T18:20:54+08:00
[INFO] ------------------------------------------------------------------------
  1. 切换到原来运行atlas-run的命令行窗口,你能够看到 相似以下的日志输入:
[INFO] [talledLocalContainer] 2021-03-01 18:21:00,379 INFO [QuickReload - Plugin Installer] [atlassian.plugin.manager.DefaultPluginManager] updatePlugin Updating plugin 'com.example.myConfluenceMacro-tests' from version '1.0.0-SNAPSHOT' to version '1.0.0-SNAPSHOT'
[INFO] [talledLocalContainer] 2021-03-01 18:21:00,379 INFO [QuickReload - Plugin Installer] [atlassian.plugin.manager.DefaultPluginManager] broadcastPluginDisabling Disabling com.example.myConfluenceMacro-tests
[INFO] [talledLocalContainer] 2021-03-01 18:21:01,629 INFO [QuickReload - Plugin Installer] [plugins.quickreload.install.PluginInstallerMechanic] installPluginImmediately
[INFO] [talledLocalContainer]                                           ^
[INFO] [talledLocalContainer]                                           |
[INFO] [talledLocalContainer]                                           |
[INFO] [talledLocalContainer]                                           |
[INFO] [talledLocalContainer]                                           |
[INFO] [talledLocalContainer]                                           |
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer]           If you can type on a Dvorak keyboard can you automatically speak Esperanto and program in Lisp?
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] Quick Reload Finished (2979 ms) - 'myConfluenceMacro-1.0.0-SNAPSHOT-tests.jar'
  1. 在浏览器里创立一个页面,插入一个宏,在抉择宏的弹窗里,你就能够看到 Helloworld这个宏了。

  1. 插入Helloworld宏后,公布,就能够看到公布后的成果

参考资料

https://developer.atlassian.c…

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理