This sample project shows how to build an ark-plugin
based on a normal java project with the tool of sofa-ark-plugin-maven-plugin
Assuming such a situation, you develop a lib, however, some dependency
conflict occurs when imported to the consumer project. To avoid this
problem, you would hope to isolate your lib with the consumer project.
Ark-Plugin
employs the mechanism of classloader isolation. It runs on
Ark-Container
, any ark-plugin
would be loaded by an independent classloader.
There are four concepts about ark-plugin
:
-
Exported Class: classes contained in
ark-plugin
,loaded by ark-plugin-classloader, but can be resolved by otherark-plugin
(if it imports) or consumer project. -
Imported Class: if a
ark-plugin
configures this item, it prefers to resolve class from otherark-plugin
which exports corresponding class. -
Exported Resource: resources contained in
ark-plugin
,loaded by ark-plugin-classloader, but can be found by otherark-plugin
(if it imports) or consumer project. -
Imported Resource: if a
ark-plugin
configures this item, it prefers to find resource from otherark-plugin
which exports corresponding resource.
The Maven plugin
of sofa-ark-plugin-maven-plugin
is provided to build a
standard ark-plugin
, and just needs some simple configurations. Details please
refer to doc
This sample project is a standard maven project, it contains two modules:
- common module: contains some classes exported.
- plugin module: contains
plugin activator
andplugin service
.
One thing should be pointed out that dependencies imported by project also can be exported.
The maven plugin of sofa-ark-plugin-maven-plugin
is configured in the pom.xml
of plugin
module, it configures as follows:
<executions>
<execution>
<id>default-cli</id>
<!-- goal executed to generate ark-plugin -->
<goals>
<goal>ark-plugin</goal>
</goals>
<configuration>
<!--can only configure no more than one activator-->
<activator>com.alipay.sofa.ark.sample.activator.SamplePluginActivator</activator>
<!-- configure exported class -->
<exported>
<!-- configure package-level exported class-->
<packages>
<package>com.alipay.sofa.ark.sample.common</package>
</packages>
<!-- configure class-level exported class -->
<classes>
<class>com.alipay.sofa.ark.sample.facade.SamplePluginService</class>
</classes>
<!-- configure exported resource -->
<resources>
<resource>Sample_Resource_Exported</resource>
</resources>
</exported>
</exported>
<!--specify destination where ark-plugin will be saved, default saved to ${project.build.directory}-->
<outputDirectory>../target</outputDirectory>
</configuration>
</execution>
</executions>
The configured items are explained as follows:
activator
: startup entry ofark-plugin
when running onark-container
; generally speaking,ark-plugin service
would be published in the entry, similar to whatSamplePluginActivator
does.exported pacakges
: the package ofcom.alipay.sofa.ark.sample.common
is exported, any class whose name start withcom.alipay.sofa.ark.sample.common
would be exported.exported classes
: the single classcom.alipay.sofa.ark.sample.facade.SamplePluginService
is exported.exported resource
: the resourceSample_Resource_Exported
is exported.outputDirectory
: specify destination where ark-plugin would be saved when execute the maven command ofmvn package
- package: execute
mvn package
, the ark-plugin file generated would be saved to the configured value ofoutputDirectory
. - install: execute
mvn install
, the ark-plugin would be installed local maven repository, its maven location would bring a classifier ofark-plugin
. - deploy: execute
mvn deploy
, just as usual practice.
As what mentioned above, the maven location of ark-plugin would bring with a classifier
of ark-plugin
, so, to import the ark-plugin generated by this sample project, you
should add the following dependency in your consumer project:
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>sample-ark-plugin</artifactId>
<classifier>ark-plugin</classifier>
<version>0.6.0-SNAPSHOT</version>
</dependency>