Ark package introduction

Updated at:

This topic describes the directory structure of standard Ark packages and how to use the official plug-in sofa-ark-maven-plugin to package and publish Ark packages.

Maven plug-ins

By default, SOFAArk provides the Maven plug-in sofa-ark-maven-plugin to package common Java projects or Spring Boot projects into standard Ark packages. Based on Fat Jar technology, you can use java -jar commands to directly start Ark packages. The coordinates of the Maven plug-in are:

<plugin>
    <groupId>com.alipay.sofa</groupId>
    <artifactId>sofa-ark-maven-plugin</artifactId>
    <version>${sofa.ark.version}</version>
</plugin>

Goals configuration

The sofa-ark-maven-plugin plug-in provides a goal: repackage to package the project into an executable Ark package, as follows:

<build>
    <plugin>
        <groupId>com.alipay.sofa</groupId>
        <artifactId>sofa-ark-maven-plugin</artifactId>
        <version>${sofa.ark.version}</version>
        <executions>
            <execution>
                <id>default-cli</id>
                <goals>
                    <goal>repackage</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
        <! -- Configuration information -->
        </configuration>
    </plugin>
</build>

Complete configuration template

The complete sofa-ark-maven-plguin plug-in configuration template is as follows:

<plugins>
    <plugin>
        <groupId>com.alipay.sofa</groupId>
        <artifactId>sofa-ark-maven-plugin</artifactId>
        <version>${sofa.ark.version}</version>
        <executions>
            <execution>
                <id>default-cli</id>
                <goals>
                    <goal>repackage</goal>
                </goals>
                <configuration>
                    <! -- The ARK package and Ark Biz package storage directory, which is the project build directory by default -->
                    <outputDirectory>./target</outputDirectory>
                    
                    <! -- Set the root directory of the application, which is used to read the ${base.dir}/conf/ark/bootstrap.application configuration file. The default value is ${project.basedir}. -->
                    <baseDir>./</baseDir>
                    
                    <! -- Generate the name of the Ark package file. The default value is ${artifactId}. -->
                    <finalName>demo-ark</finalName>
                    
                    <! -- Whether to skip the execution of goal:repackage. Default value: false. -->
                    <skip>false</skip>
                    
                    <! -- Whether to package, install, and publish Ark Biz. For more information, see the Ark Biz documentation. Default value: false. -->
                    <attach>true</attach>
                    
                    <! -- Set the classifier of the ark package. This parameter is empty by default. -->
                    <arkClassifier>ark</arkClassifier>
                    
                    <! -- Set the classifier of Ark Biz. The default value is ark-biz. -->
                    <bizClassifier>ark-biz</bizClassifier>
                    
                    <! -- Set the biz name of Ark Biz. The default value is ${artifactId}. -->
                    <bizName>demo-ark</bizName>
                    
                    <! -- Set the biz version of Ark Biz. The default value is ${artifactId}. -->
                    <bizVersion>0.0.1</bizVersion>
                    
                    <! -- Set the startup priority of Ark Biz, the smaller the value, the higher the priority,${artifactId}-->
                    <priority>100</priority>
                    
                    <! -Set the startup entry of Ark Biz. By default, the entry class with org.springframework.boot.autoconfigure.SpringBootApplication annotation and main method will be searched for -->
                    <mainClass>com.alipay.sofa.xx.xx.MainEntry</mainClass>
                    
                    <! -- Set whether to package the dependency with scope=provided. Default value: false. -->
                    <packageProvided>false</packageProvided>
                    
                    <! -- Set whether to generate Biz packages. Default value: true. -->
                    <keepArkBizJar>true</keepArkBizJar>
                    
                    <! -- For web applications, set the context path. The default value is /-->
                    <webContextPath>/</webContextPath>
                    
                    <! -- Exclude the specified package dependencies when you package Ark Biz. Format: ${groupId:artifactId} or ${groupId:artifactId:classifier}-->
                    <excludes>
                        <exclude>org.apache.commons:commons-lang3</exclude>
                    </excludes>
                    
                    <! -- Exclude package dependencies that have the same groupId as the specified groupId when packaging Ark Biz -->
                    <excludeGroupIds>
                        <excludeGroupId>org.springframework</excludeGroupId>
                    </excludeGroupIds>
                    
                    <! -- Exclude package dependencies that have the same artifact ID as the Ark Biz package. -->
                    <excludeArtifactIds>
                        <excludeArtifactId>sofa-ark-spi</excludeArtifactId>
                    </excludeArtifactIds>
                    
                    <! -- When you package Ark Biz, configure classes that are not indexed from the Ark Plugin. By default, Ark Biz preferentially indexes the exported classes of all Ark Plugins, 
                            After this configuration is added, Ark Biz will only load the class inside Ark Biz, and Ark Plugin will no longer be entrusted to load it first -->
                    <denyImportClasses>
                        <class>com.alipay.sofa.SampleClass1</class>
                        <class>com.alipay.sofa.SampleClass2</class>
                    </denyImportClasses>
                    
                    <! -- Corresponding to the denyImportClasses configuration, you can configure the package level -->
                    <denyImportPackages>
                        <package>com.alipay.sofa</package>
                        <package>org.springframework.*</package>
                    </denyImportPackages>
                    
                    <! -- Configure resources that are not indexed from the Ark Plugin when you package Ark Biz. By default, Ark Biz preferentially indexes the exported resources of all Ark Plugins,
                            After adding this configuration, Ark Biz will only look for this resource inside Ark Biz, not from Ark Plugin -->
                    <denyImportResources>
                        <resource>META-INF/spring/test1.xml</resource>
                        <resource>META-INF/spring/test2.xml</resource>
                    </denyImportResources>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

configuration items meaning can refer to the above notes.

Build

Take the Spring Boot Web project as an example. To generate a standard Ark package, perform the following steps:

  1. Configure the sofa-ark-maven-plugin plug-in in the pom.xml file of the Web module by referring to the configuration template.

  2. Click the mvn pacakge command in the web module directory or application root directory to generate Ark packages and Ark Biz files in the configured outputDirectory directory. The default names are Web module ${artifactId} and ${artifactId}-ark-biz.

    You can also use arkClassifier and bizClassifier to set the classifier. If you run the mvn install command, the Ark package is installed to the local repository. If attach is set to true, Ark Biz is installed to the local repository at the same time.

Publish

Configure the repository address in the project master pom, and then hit the mvn deploy command to publish the Ark package.

Important

If the attach is set to true ,Ark Biz will also be published to the repository. In addition, the Ark Biz release package contains classifier = ark-biz by default. You can use the bizClassifier parameter to configure the Ark Biz classifier.

Typical directory structure of Ark packages

Take packaging Ark packages as an example. The following figure shows the directory structure of the Ark packages generated by packaging a common Spring Boot Web application:

.
├── META-INF
│ └── MANIFEST.MF
├── SOFA-ARK
│ ├── biz
│ │ └ ── sofa-ark-sample-springboot-ark-0.6.0-ark-biz.jar
│ └── container
│ └── sofa-ark-all-0.6.0.jar
├── com
│ └── alipay
│ └── sofa
│ └── ark
│ ├── bootstrap
│ ├── common
│ ├── loader
│ └── spi
└── conf
     └── ark
          └── bootstrap.properties 

The files and directories related to the preceding directory structure are described as follows:

  • META-INF/MANIFEST.MF: Records the metadata of the Ark package. The most critical information is the startup entry class Main-Class of the Ark package. The file content is similar to the following:

    Manifest-Version:1.0
    web-context-path:/
    Archiver-Version:PlexusArchiver
    Built-By: qilong.zql
    Ark-Biz-Name: sofa-ark-sample-springboot-ark
    Sofa-Ark-Version:0.6.0
    deny-import-packages:
    priority:100
    Main-Class: com.alipay.sofa.ark.bootstrap.ArkLauncher
    deny-import-classes:
    Ark-Container-Root: SOFA-ARK/container/
    deny-import-resources:
    Ark-Biz-Version:0.6.0
    Created-By:ApacheMaven3.2.5
    Build-Jdk:1.8.0_101

    As you can see, the Ark package startup entry class is com.alipay.sofa.ark.bootstrap.ArkLauncher.

  • com/alipay/sofa/ark/*: Stores the bootstrap classes necessary to start the Ark package using the java -jar command.

  • SOFA-ARK/container: Store the ark container dependency package as follows:

    <dependency>
         <groupId>com.alipay.sofa</groupId>
         <artifactId>sofa-ark-all</artifactId>
         <version>${sofa.ark.version}</version>
    </dependency>
  • SOFA-ARK/biz: stores all Ark Biz packages, because the sample project does not depend on other Ark Biz packages, so only its own Ark Biz packages are stored.

  • SOFA-ARK/plugin: In the sample project, this directory is not generated because the project does not depend on other Ark plugins.

  • conf/ark/properties: the configuration file of the SOFAArk container. In the sample project, the path for generating SOFAArk logs is set.