Updated on 2022-02-24 GMT+08:00

Packaging the Codec

This topic describes how to package the codec and prepare the package.

Packaging the Codec Using Maven

After the codec is programmed, use Maven to package the codec. On the Windows OS, perform the following steps:

  1. Open the DOS window and access the directory where the pom.xml file is located.
  2. Run mvn package.
  3. After BUILD SUCCESS is displayed in the DOS window, open the target folder in the same directory as the pom.xml file to obtain the .jar package.

    The naming rule of the .jar package is as follows: device type-manufacturer ID-device model-version.jar, for example: WaterMeter-Huawei-NBIoTDevice-version.jar.

    Figure 1 Structure of the .jar file
    • The com directory stores class files.
    • The META-INF directory stores description files of .jar packages under the OSGi framework, which are generated based on configurations in the pom.xml file.
    • The OSGI-INF directory stores service configuration files and is used to register the codec as a service for the platform to call. (Only one .xml file can be called.)
    • Other .jar packages are .jar packages referenced by codecs.

Preparing a Codec Package

  1. Create a folder named package, which contains the preload/ sub-folder.
  2. Place the packaged .jar package in the preload/ folder.

    Figure 2 Structure of the codec package

  3. In the package folder, create the package-info.json file. The fields and templates in this file are described as follows:

    NOTE:

    The package-info.json file is encoded using UTF-8 without BOM. Only English characters are supported.

    Table 1 Description of fields in the package-info.json file

    Field

    Description

    Mandatory or Optional

    specVersion

    Specifies the version of the description file. The value is fixed at 1.0.

    Mandatory

    fileName

    Specifies the name of the software package. The value is fixed at codec-demo.

    Mandatory

    version

    Specifies the version number of the software package. The version of the package.zip file must be the same as the value of bundleVersion.

    Mandatory

    deviceType

    Specifies the device type, which must be the same as that defined in the profile file.

    Mandatory

    manufacturerName

    Specifies the manufacturer name, which must be the same as that defined in the profile file. Otherwise, the package-info.json file cannot be uploaded to the IoT platform.

    Mandatory

    model

    Specifies the product model, which must be the same as that defined in the profile file.

    Mandatory

    platform

    Specifies the platform type, which is the operating system of the IoT platform on which the codec package runs. The value is fixed at linux.

    Mandatory

    packageType

    Specifies the software package type. This field is used to describe the IoT platform module where the codec is deployed. The value is fixed at CIGPlugin.

    Mandatory

    date

    Specifies the time when a packet is sent. The format is as follows: yyyy-MM-dd HH-mm-ss. For example, 2017-05-06 20:48:59.

    Optional

    description

    Specifies the self-defined description about the software package.

    Optional

    ignoreList

    Specifies the list of bundles to be ignored. The default value is null.

    Mandatory

    bundles

    Specifies the description of a bundle.

    NOTE:

    A bundle is a .jar package in a compressed package. Only one bundle needs to be described.

    Mandatory

    Table 2 Description of the bundles field

    Field

    Description

    Mandatory or Optional

    bundleName

    Specifies the bundle name, which is consistent with the value of Bundle-SymbolicName in the pom.xml file.

    Mandatory

    bundleVersion

    Specifies the bundle version, which must be the same as the value of version.

    Mandatory

    priority

    Specifies the bundle priority. This parameter can be set to the default value 5.

    Mandatory

    fileName

    Specifies the codec file name.

    Mandatory

    bundleDesc

    Describes the bundle function.

    Mandatory

    versionDesc

    Describes the functions and features of different versions.

    Mandatory

    Template of the package-info.json file

    {
        "specVersion":"1.0",
        "fileName":"codec-demo",
        "version":"1.0.0",
        "deviceType":"WaterMeter",
        "manufacturerName":"Huawei",
        "model":"NBIoTDevice",
        "description":"codec",
        "platform":"linux",
        "packageType":"CIGPlugin",
        "date":"2017-02-06 12:16:59",
        "ignoreList":[],
        "bundles":[
        {
            "bundleName": "WaterMeter-Huawei-NBIoTDevice",
            "bundleVersion": "1.0.0",
            "priority":5,
            "fileName": "WaterMeter-Huawei-NBIoTDevice-1.0.0.jar",
            "bundleDesc":"",
            "versionDesc":""
        }]
    }

  4. Select all files in the package folder and compress them into a package.zip file.

    NOTE:

    The package.zip file cannot contain the package directory.