jRPM programming example


It's quite easy to use jRPM. In the following section you will see how to generate a peace of code that will read tags out of a RPM file.

Reading tags

First of all you have to create an instance of a RPM file. This is done with the class com.jguild.jrpm.io.RPMFile.

RPMFile rpmFile = new RPMFile(new File("C:\test.rpm"));

After that you can read tags out of the RPM file. For example you can read the name, version, description out of the file. For a list of tags consult the api documentation for the class com.jguild.jrpm.io.constant.RPMHeaderTag or the RPM file spec.

DataTypeIf tag = rpmFile.getTag("name")

The DataTypeIf can be cast to a specific RPM type. So specific actions can be taken for each type.

   if (tag instanceof STRING) {
      STRING rpmString = (STRING) tag;
      String jString = rpmString.getData();
      System.out.println("Name = " + jString);


RPM provides the capability to save more than one locale in the file. So there can be one description in english and one in german. This informations are saved as I18NSTRINGs. All locales that are provided by a RPM file can be read with the function getLocales().

String[] locales = tag.getLocales().

The locale for a RPM file can be specified by the setLocale() method. This locale is automaticly returned for each I18NSTRING. So you can switch between different locales.

   System.out.println("German description : " + 
   System.out.println("English description : " +