# Add .JAR for using classes in Jython scripts

**URL:** <https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529>\
**Category:** 3rd Party Modules\
**Created:** [January 9, 2017, 10:37am UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529 "2017-01-09T10:37:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![uborzz](https://avatars.discourse-cdn.com/v4/letter/u/58956e/32.png) [@uborzz](https://forum.inductiveautomation.com/u/uborzz)\
**Post date:** [January 9, 2017, 10:37am UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/1 "2017-01-09T10:37:10Z")

</div>

Hello!

I started playing with ignition some weeks ago and I would like to use in python some classes/methods from java libraries that are not included in the standard libraries. (i.e. vectorz, poi-ooxml…)

What is the best way to do this?

I’ve been reading the SDK programmers guide and started learning about Java and maven. I’ve installed eclipse, maven, build a module from the gateway-designer-client archetype, configured the hooks with "import " and added to the pom.xml files the libs/versions as dependencies.

After packaging the module (correctly -apparently-, with some .jar and .pack.jar.gz files that maven considers necessary inside the .modl) and signing, I can upload it to my gateway and it shows as “Running”, but I still can’t use the libraries in the playground.

Couldn’t see an example of this in the ignition-sdk-examples. Is this the way to go? Is there another way to use java libraries in python without using a module?

Thanks!  
Regards!

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 9, 2017, 5:29pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/2 "2017-01-09T17:29:08Z")

</div>

If you’re trying to use these libraries in the script playground you have to make sure your module loads them in the appropriate scope(s).

For access in scripting you probably want to load them into all 3 scopes (C, D, G).

---

<div class="post-metadata">

**Author:** ![uborzz](https://avatars.discourse-cdn.com/v4/letter/u/58956e/32.png) [@uborzz](https://forum.inductiveautomation.com/u/uborzz)\
**Post date:** [January 10, 2017, 11:55am UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/3 "2017-01-10T11:55:47Z")

</div>

Hello Kevin, thanks for the answer.

When you say “your module loads them in the appropriate scope(s)” you mean import them in the 3 hook classes or there’s more to be done?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 10, 2017, 4:50pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/4 "2017-01-10T16:50:57Z")

</div>

You just need an empty hook class for each scope, to make sure each scope depends on the jar(s) you’re trying to import, and to make sure the module.xml declares the dependency on the jar in all 3 scopes and has all 3 hooks specified.

---

<div class="post-metadata">

**Author:** ![uborzz](https://avatars.discourse-cdn.com/v4/letter/u/58956e/32.png) [@uborzz](https://forum.inductiveautomation.com/u/uborzz)\
**Post date:** [January 17, 2017, 3:17pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/5 "2017-01-17T15:17:05Z")

</div>

Hello!

Thanks Kevin for your responses. I’ve managed to make it work in the designer & client. No luck in the gateway ☹.

Libraries are not being loaded in the gateway, when called I get errors (no class found). Libs seems OK (gateway scripts work when libs are placed in the libs folder manually).

I’m working on reading microsoft files and I’ve found Apache Poi is already one of the libs by default in the gateway (but looks like its not complete O\_o), anyways I’m trying to load with my module an older version. As I said, this went OK in D and C.

Any idea? 😛

Thanks.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [January 17, 2017, 3:58pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/6 "2017-01-17T15:58:57Z")

</div>

Ah, yeah. It’s not going to work with regular dependencies in the gateway because of how modules are loaded in their own ClassLoader.

There’s one trick you can use, but your module won’t be able reloadable/restartable if you do this. In your module.xml, instead of using the ‘jar’ element for the gateway scope, use ‘export’:

```auto
    <export scope="G">name-of-jar.jar</export>
```

Ignition will load this jar in a ClassLoader further up in the hierarchy and it should be available to scripting this way…

---

<div class="post-metadata">

**Author:** ![Kevin.Collins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.collins/32/13497_2.png) [@Kevin.Collins](https://forum.inductiveautomation.com/u/Kevin.Collins)\
**Post date:** [September 28, 2017, 2:38pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/7 "2017-09-28T14:38:39Z")

</div>

Kevin, is there a way to get the `<export>` tag to be included in the module.xml via the Maven build? I’m trying to find where I can configure that in the build pom, but not having any luck. Thanks!

---

<div class="post-metadata">

**Author:** ![PerryAJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/perryaj/32/3281_2.png) [@PerryAJ](https://forum.inductiveautomation.com/u/PerryAJ)\
**Post date:** [September 28, 2017, 10:13pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/8 "2017-09-28T22:13:43Z")

</div>

> Kevin, is there a way to get the tag to be included in the module.xml via the Maven build? I'm trying to find where I can configure that in the build pom, but not having any luck. Thanks!

The export functionality is not part of the supported/documented public api, so it's not currently supported in the module plugin. The functionality does present some limitations/potential issues around gw stability, so I am not sure we want to support its wide use.

---

<div class="post-metadata">

**Author:** ![Kevin.Collins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.collins/32/13497_2.png) [@Kevin.Collins](https://forum.inductiveautomation.com/u/Kevin.Collins)\
**Post date:** [September 28, 2017, 10:25pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/9 "2017-09-28T22:25:35Z")

</div>

Cool, I can appreciate that… At least now I know it isn’t just something I’m not aware of… I think for my purposes I can wrap the required functionality so I don’t need to expose libraries at the root level… Thanks!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 29, 2017, 12:44pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/10 "2017-09-29T12:44:28Z")

</div>

> [@PerryAJ](#):
>
> not currently supported in the module plugin

Ant to the rescue! But yeah, don't do it. You can make a script module with static public final Class\<?\> variables set to the .class elements you wish to expose. Much safer, and gives your user short names for those classes.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [April 23, 2019, 7:15am UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/11 "2019-04-23T07:15:07Z")

</div>

> [@Kevin.Herron](#):
>
> If you’re trying to use these libraries in the script playground you have to make sure your module loads them in the appropriate scope(s).
> 
> For access in scripting you probably want to load them into all 3 scopes (C, D, G).

Hi Kevin,

I am using the pubnub jar file in my gateway scripts on script playground. I took a short cut and just copied the pubnub jar file in lib/core/gateway folder. For Ignition 7.9.10 it works fine immediately after copying the jar. However for Ignition version 8.0, it didn't work! I had to restart the Ignition gateway then it started working! Why in Ignition 8 it requires a restart of gateway? Restart is undesirable as it will interrupt a running gateway server ! How can I avoid it? By writing an empty gateway hook that references (imports) the one of the libraries in the jar? Is there any other simpler way without having to build and install an Ignition module?

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [May 1, 2019, 7:38pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/12 "2019-05-01T19:38:29Z")

</div>

Hi @PRAMANJ, I’m curious how you achieved this.  
I’m also testing on a 7.9.10 install and was unable to import the Logger.class as a test.  
I tried dropping pubnub-3.4.jar into the lib/core/common directory. When I ran `from com.pubnub.api import Logger` in the script console I got `ImportError: No module named pubnub`

I’m trying to learn more about these areas of Ignition so any insight would be greatly appreciated.  
My end goal would be to achieve exactly what the OP wanted to do with regards to poi-ooxml-4.1.0.jar.  
My idea is to get this jar working as you described, then trying to build a module for it.

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [May 1, 2019, 8:39pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/13 "2019-05-01T20:39:14Z")

</div>

I was able to get this to work.

I used pack200 to create a pack.gz and placed the jar and the pack.gz files in the lib/core/common.  
I restarted the gateway and my designer and I was able to run `from com.pubnub.api import Logger` without any errors.

Thanks to @Kevin.Herron in this post: [Adding java custom classes to Ignition](http://forum.inductiveautomation.com/t/adding-java-custom-classes-to-ignition/15202/2?u=code_skin)

NOTE\* his disclaimer about official support and the SDK is the way to go.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 2, 2019, 4:18am UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/14 "2019-05-02T04:18:15Z")

</div>

I placed my jars in gateway scope and I was able to access thru gateway scripts in 7.9.10. However for version 8, I too had to restart the gateway and designer once for it to work.  
Are you using these jars from modules or from scripts?

> [@code\_skin](#):
>
> NOTE\* his disclaimer about official support and the SDK is the way to go.

Of course sdk is the recommended way but a dreaded the whole process of building empty modules and keeping versions of it for each version of Ignition. So I took the shortcut and it worked (atleast for 7.9.10)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 2, 2019, 11:25am UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/15 "2019-05-02T11:25:06Z")

</div>

> [@prafull\_j](#):
>
> building empty modules

Then don't build empty modules. Put the jars you are deploying into the modules like they're supposed to be, with a script class that exposes the import objects from the jars in the Ignition system.\* namespace. _ **You should do the work to make it easy on your potential customers.** _ Don't make them responsible for placing jars in the right places. They might not have convenient filesystem access, but be able to use the module install page in the gateway.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 2, 2019, 12:18pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/16 "2019-05-02T12:18:15Z")

</div>

> [@pturmel](#):
>
> Put the jars you are deploying into the modules like they’re supposed to be,

But I don't have any modules ! I simply have jython scripts in gateway that use the libraries from this jar! If at all I have to build a module in gateway scope, then I have to use the skeleton gateway module that's auto generated by maven archetypes for Ignition, and import some functions from these jars without using any of them it it and build the module! That's what I meant by empty module. I hope my point is clear, or I am missing something?

> [@pturmel](#):
>
> with a script class that exposes the import objects from the jars in the Ignition system

Not clear! I am including an import statement in the skeleton module which uses some of the functions from this jar. Hope that's what you mean? I am actually not using any function in the code of the module.

> [@pturmel](#):
>
> _ **You should do the work to make it easy on your potential customers.** _ Don’t make them responsible for placing jars in the right places. They might not have convenient filesystem access, but be able to use the module install page in the gateway.

I guess I will have to eventually make such an empty module and try to Install in Ignition as a regular module which will install the jars in appropriate directories. The biggest advantage besides users convenience is that they can be installed in gateway without having to restart it!

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [May 2, 2019, 12:53pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/17 "2019-05-02T12:53:05Z")

</div>

Scripts. I'm working my way to building a module for it so users can use the system.\* namespace in there scripts.

My end goal is to expose the apache poi 4.1.0 to end users. I've been digging around the forums and I'm wondering if my end goal is not possible? Kevin mentions a weird corner case about possible conflicts with the reporting module because it uses poi-3.14.

> [@Adding java custom classes to Ignition](http://forum.inductiveautomation.com/t/adding-java-custom-classes-to-ignition/15202/18):
>
> I just unzipped the jar file for that version and looked. You’re going to run into the same potential conflict as long as the Reporting module is installed. You’ve hit a weird corner case in the architecture of the Client and Designer and its flat class path. If you loaded POI in the Gateway scope and all your interactions with the library took place there you’d be okay.

I'm looking for a kick start in the right direction (Uninstalling the reporting module isn't an option for our client); is 4.1.0 not a good idea because of the reporting module? Is it a safer bet to use the same version as the reporting module? Is it possible to just access the existing POI library from all scopes?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 2, 2019, 1:03pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/18 "2019-05-02T13:03:11Z")

</div>

> [@code\_skin](#):
>
> is 4.1.0 not a good idea because of the reporting module? Is it a safer bet to use the same version as the reporting module?

Yes, you'll have to use the same version as Reporting.

> [@code\_skin](#):
>
> Is it possible to just access the existing POI library from all scopes?

Only if your module adds it to all scopes. It's added to C/D by Reporting, not gateway.

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [May 2, 2019, 2:09pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/19 "2019-05-02T14:09:31Z")

</div>

How come `import org.apache.poi` fails to import in the designer if the reporting modules adds it to the D scope?

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [May 2, 2019, 2:41pm UTC](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529/20 "2019-05-02T14:41:15Z")

</div>

> [@code\_skin](#):
>
> My end goal is to expose the apache poi 4.1.0 to end users. I’ve been digging around the forums and I’m wondering if my end goal is not possible? Kevin mentions a weird corner case about possible conflicts with the reporting module because it uses poi-3.14.

I would think it's possible since there already exists a third-party wrapper module for Apache POI, by Perfect Abstractions: [http://blog.perfectabstractions.com/2017/04/05/using-the-pa-office-document-module/](http://blog.perfectabstractions.com/2017/04/05/using-the-pa-office-document-module/)

[Next page](https://forum.inductiveautomation.com/t/add-jar-for-using-classes-in-jython-scripts/12529.md?page=2)
