Package into Ark Plugin

Update time: 2019-10-16


This sample project demonstrates how to use Maven plugins to package a general Java project into an Ark plugin that meets the standard specifications.


In actual development, dependency conflicts often occur. Suppose we have developed a class library named sample-lib, and it might conflict with the existing dependencies when the business application is imported. At this point, we hope the library can be isolated from other business dependencies, without negotiating with each other over dependency package versions. Ark Plugin is exactly the result of our best practice under this demand background. It runs on top of the Ark Container, which is loaded by a container. Any Ark Plugin is loaded by a separate ClassLoader to be isolated from each other. There are four concepts of Ark Plugin: * Import class: When the plugin starts up, a plugin used to export the class is first delegated to load the class. If that fails, it will attempt to load from inside this plugin;

  • Export class: If the class has been imported by other plugins, it will be first loaded from this plugin;

  • Import resource: When the plugin is searching for resources, a plugin used to export the class is first delegated to load the class. If that fails, it will attempt to load from inside this plugin.

  • Export resource: If the resource has been imported by other plugins, it will be first loaded from this plugin;

Refer to the plugin specifications for more details


Upon simple configurations, the officially provided Maven plugin sofa-ark-plugin-maven-plugin can package common Java projects into a standard-format Ark Plugin. The coordinates of Maven plugin are:


For more information, see the plugin configuration document

Getting started

Based on this sample project, we will describe how to build an Ark plugin step by step.

Create a Standard Maven Project

This is a standard Maven project consisting of two modules: * The common module: contains the plugin export class

  • The plugin module: contains interface implementation class and a plugin service class. The plugin packaging tool sofa-ark-plugin-maven-plugin can be configured in the module’s pom.xml file;

Configuring Packaging Plugin

Package the plugin in the pom.xml file according to the following configurations:



                        <!--can only configure no more than one activator-->

                        <!-- configure exported class -->
                            <!-- configure package-level exported class-->

                            <!-- configure class-level exported class -->

                        <!--specify destination where ark-plugin will be saved, default saved to ${}-->



In the sample project, we have configured only a fraction of the items, but they are enough to produce an executable Ark Plugin. The meaning of each configuration item is shown below: * activator: The entry class of the Ark container startup plugin. At most one activator can be configured. The plugin’s activator will generally execute a couple of initializations such as the plugin service publish. In this sample project, the plugin service is published.

  • Export package: The package-level export class configuration. All classes inside the plugins prefixed with the name of the export package, including the plugin’s third-party dependency packages, will be exported;

  • Export class: Configure this to export specified classes with precise class names;

  • outputDirectory: The output directory into which the generated Ark plugin is placed after mvn package is executed;

Note that in the sample project, we have only exported the classes created by the project. In actual use, however, we can also export the third-party packages that the project depends on.

Packaging, Installation, Publishing, and Introducing

Like a common project, we can simply use mvn package, mvn install, or mvn deploy to install and publish plugins. Note that the Maven coordinates of Ark Plugin that is published by default will add the classifier=ark-plugin. In this sample project, if we want to use that ark plugin, we need to configure the dependencies as follows: