Package into Ark JAR

Update time: 0001-01-01


This sample project shows how to build an executable-ark-jar based on a springboot project with the tool of sofa-ark-maven-plugin.


As this project depends on the ark-plugin generated by the project of sample-ark-plugin, please ensure the sample sample-ark-plugin installed in your local maven repository before run this project.


The Maven plugin of sofa-ark-maven-plugin is provided to build a standard executable-ark-jar, and just needs some simple configurations. Its maven coordinates is:


Refer to the document of plugin use for details

Step By Step

Based on the sample project, we will describe step by step how to package a Spring Boot Web project to an executable Ark package

Creating Spring Boot Web Project

Download a standard Spring Boot Web project from the official website

Introducing sample-ark-plugin

Configure items as follows under the main pom.xml of the project, and add the Ark Plugin dependency generated from another sample project, reference documents


Configuring Packaging Plugin

Configure the Maven plugin (sofa-Ark-maven-plugin) as follows under the main pom.xml of the project:

                    <!--goal executed to generate executable-ark-jar -->
                        <!--specify destination where executable-ark-jar will be saved, default saved to ${}-->
                        <!--default none-->

In this sample project, we have configured only a fraction of the items, but they are enough to generate an executable Ark package. The meaning of each configuration item is shown below: * outputDirectory: the directory for the output Ark package files after packaging of mvn package;

  • arkClassifier: the value of classifier included in the Maven coordinates of the Ark specified for release, which is null by default;

Note that arkClassifier is null by default. If you do not specify a classifier, the Jar package uploaded to the repository is actually an executable Ark package. If you need to distinguish it from common packaging, you need to configure a value for this item.

Packaging, Installation, and Release

Similar to the operation of common projects, you can complete the installation and release of plugin package with mvn package, mvn install, and mvn deploy;

Run the application

We offer two ways to start project applications on the Ark container: with the command line or in the IDE. To start in the IDE, additional dependencies need to be added. With the command line, we can directly use java -jar to start project applications. Now we will talk about how to start Ark applications in the IDE;

  • Spring Boot project: We only need to add the following dependency:
  • Common Java projects: Compared with Spring Boot projects, we need to add another dependency to common Java projects:

In addition, we need to execute container start at the very beginning of the main approach of the project, as follows:

public class Application{
    public static void main(String[] args) { 

Running Test

SOFAArk provides two implementation classes of org.junit.runner.Runner: ArkJUnit4Runner and ArkBootRunner, which are used to integrate JUnit4 test framework and Spring Test respectively. For TestNG test framework, the annotation @TestNGOnArk is provided. For any TestNG test cases, only those annotated with @TestNGOnArk will run above the Ark Container, otherwise they are the same as common cases.


ArkJUnit4Runner: Similar to JUnit4, we can run common JUnit4 test cases above the SOFAArk container with the annotation ArkJUnit4Runner. A sample code is as follows:

public class UnitTest {

    public void test() {


The use of ArkJUnit4Runner and JUnit4 is almost the same, and other features of JUnit4 test framework are fully compatible,


ArkBootRunner is similar to SpringRunner, refer to the documentto learn the usage of SpringRunner. To be able to run Spring Boot test cases above the SOFAArk container, we only need to use @RunWith(ArkBootRunner.class) to replace @RunWith(SpringRunner.class); A sample code is as follows:

@SpringBootTest(classes = SpringbootDemoApplication.class)
public class IntegrationTest {

    private SampleService sampleService;

    public void test() {
        Assert.assertTrue("A Sample Service".equals(sampleService.service()));


The use of ArkBootRunner and SpringRunner is almost the same;


The annotation @TestNGOnArk is provided by SOFAArk for developers to mark which TestNG cases run above SOFAArk and which TestNG cases just run normally. For example:

public class TestNGTest {

    public static final String TEST_CLASSLOADER = "";

    public void test() {
        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
        ClassLoader loader = this.getClass().getClassLoader();


The above case is annotated with @TestNGTest. So when executing it, Ark Container will start first.