How do I pack an ISO 8583 message?

The code snippet below show you how to pack an ISO 8583 message.

package org.kodejava.example.jpos;

import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.packager.GenericPackager;


public class PackISOMessage {
    public static void main(String[] args) {
        PackISOMessage iso = new PackISOMessage();
        try {
            String message = iso.buildISOMessage();
            System.out.printf("Message = %s", message);
        } catch (Exception e) {

    private String buildISOMessage() throws Exception {
        try {
            // Load package from resources directory.
            InputStream is = getClass().getResourceAsStream("/fields.xml");
            GenericPackager packager = new GenericPackager(is);

            ISOMsg isoMsg = new ISOMsg();

            isoMsg.set(3, "000010");
            isoMsg.set(4, "1500");
            isoMsg.set(7, "1206041200");
            isoMsg.set(11, "000001");
            isoMsg.set(41, "12340001");
            isoMsg.set(49, "840");

            byte[] result = isoMsg.pack();
            return new String(result);
        } catch (ISOException e) {
            throw new Exception(e);

    private void printISOMessage(ISOMsg isoMsg) {
        try {
            System.out.printf("MTI = %s%n", isoMsg.getMTI());
            for (int i = 1; i <= isoMsg.getMaxField(); i++) {
                if (isoMsg.hasField(i)) {
                    System.out.printf("Field (%s) = %s%n", i, isoMsg.getString(i));
        } catch (ISOException e) {

When you run the program you’ll get the following output:

MTI = 0200
Field (3) = 000010
Field (4) = 1500
Field (7) = 1206041200
Field (11) = 000001
Field (41) = 12340001
Field (49) = 840
Message = 02003220000000808000000010000000001500120604120000000112340001840

The xml packager (fields.xml) can be downloaded from the following link: fields.xml.

Maven Dependency

<!-- -->

Wayan Saryada

Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. You can support my works by donating here. Thank you 🥳


  1. I get error:

    at com.mycompany.mavenproject2.PackISOMessage.buildISOMessage(
        at com.mycompany.mavenproject2.PackISOMessage.main(
    • java.lang.Exception: org.jpos.iso.ISOException: (
          at com.mycompany.mavenproject2.PackISOMessage.buildISOMessage(
          at com.mycompany.mavenproject2.PackISOMessage.main(
      Caused by: org.jpos.iso.ISOException: (
    • Hi Tony,

      I think the error because it cannot find the fields.xml file. I am using Maven, in this case I place the fields.xml file inside the resources directory (src/main/resources/fields.xml).

      Instead of loading the packager file as a resource you can also do something like this:

      String filename = "D:/jpos/fields.xml";
      GenericPackager packager = new GenericPackager(filename);
  2. I created a project named mavenproject2 and placed the fields.xml in cfg/packager but the error still there.

    InputStream is = getClass().getResourceAsStream("mavenproject2/cfg/packager/fields.xml");
    GenericPackager packager = new GenericPackager(is);
  3. Error while compiling sample ISO Message Program:

    Exception in thread "main" java.lang.UnsupportedClassVersionError: org/jpos/iso/ISOException : Unsupported major.minor version 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(
        at Method)
        at java.lang.ClassLoader.loadClass(
        at sun.misc.Launcher$AppClassLoader.loadClass(
        at java.lang.ClassLoader.loadClass(
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(
        at java.lang.Class.getMethod0(
        at java.lang.Class.getMethod(
        at sun.launcher.LauncherHelper.getMainMethod(
        at sun.launcher.LauncherHelper.checkAndLoadMain(

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.