Thursday, May 26, 2011

Packaging an external library as a module

As I've been working with programming modules for Ignition, I've needed to use certain libraries along with my projects.

One way to do this: simply include the library's jars in your .modl file, and include them in your module.xml. This will make the library accessible for your module's classes' classloader.

What if the library is very large, though? This makes development take longer, since every module load requires reloading the entire library.

The solution I came up with was to package the library in its own module.

1) Grab the library's .jar files, and throw them in a directory.
2) Create a module.xml, like what I have below.
3) Package these in a .zip file, and change the extention to .modl

My library's module.xml:
<?xml version="1.0" encoding="UTF-8"?>
  <name>Apache CXF</name>
  <description>The full Apache CXF 2.4.0 library and supporting libraries.</description>
  <!-- All the Apache CXF and CXF support libraries -->
  <jar scope="DG">antlr-2.7.7.jar</jar>
  <jar scope="DG">aopalliance-1.0.jar</jar>
  <jar scope="DG">asm-3.3.jar</jar>

Then, in your main module's module.xml, include this module as a dependency.

My main module.xml:
<?xml version="1.0" encoding="UTF-8"?>

  <depends scope="G">ApacheCXF</depends>
  <depends scope="D">ApacheCXF</depends>



Note: A module can't have two dependencies. If your module already depends on fpmi, you'll need to move that dependency to the library module, and have your module just depend on the library module. So: "Your module" ->(depends)-> "Library module" ->(depends)->"fpmi"

Note 2: Your module will still load, even if it's missing dependencies. In your module's start up, make sure to check for the library's presence, and fault your module if it's not there.

Ignition Version: 7.2 (7.2.5)


Sasi K said...

Hi Kevin,

We are trying with this method. However, How to load the Library module into Ignition ? We tried to download the Library.modl and Gateway shows error. The error description not visible in Gateway Console / wrapper.log.

Thank you

Kevin McClusky said...

Without Ignition giving error information, it's a little hard to say what's going on.

You might check to make sure that when you packaged the .zip file, you didn't accidently add in any subdirectories. (i.e. When you double click the zip, you should immediately see files.)

You could also grab the playground project from this blog, build that as a module, and make sure it works. If it does, you could compare the module.xml file from it to your module.xml file used in your Library.modl.

If you're still having problems, I'd be happy to take a look at your module. Feel free to send me a direct message on the Inductive Automation forums.

Good luck!

Sasi K said...

Thank you Kevin for your Suggestion. We found our mistake and It works great.

Fausto said...

Hi Kevin,

could you please give more details about this procedure? I'm new to the Ignition SDK, and i'm having some difficulties.
For instance, where the created .modl file should be placed?
I want to use a library (custom made), inside that simpletagprovider project that the ignition comes with.

Post a Comment