# Accessing built-in JAVA libraries from jython scripts

**URL:** <https://forum.inductiveautomation.com/t/accessing-built-in-java-libraries-from-jython-scripts/29417>\
**Category:** Module Development\
**Tags:** scripting\
**Created:** [October 26, 2019, 7:21am UTC](https://forum.inductiveautomation.com/t/accessing-built-in-java-libraries-from-jython-scripts/29417 "2019-10-26T07:21:12Z")\
**Posts on this page:** 10\
**Page:** 1

<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:** [October 26, 2019, 7:21am UTC](https://forum.inductiveautomation.com/t/accessing-built-in-java-libraries-from-jython-scripts/29417/1 "2019-10-26T07:21:12Z")

</div>

Importing packages in client/gateway scripts with commands like

from javax.swing import \*  
from [java.net](http://java.net) import \*

in the client or gateway scripts gives error like "NameError: name 'JFrame' is not defined" etc  
Do these packages have to be copied in Ignition/lib/core/client or gateway folders? These are built libraries of java , why they are not visible in scripts? How to access the builtin java libraries from our scripts? Can we access only the libraries hat are supported by scripting system libraries of Ignition?

---

<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:** [October 26, 2019, 12:53pm UTC](https://forum.inductiveautomation.com/t/accessing-built-in-java-libraries-from-jython-scripts/29417/2 "2019-10-26T12:53:42Z")

</div>

I don’t think the \* imports work for Java packages in scripting.

Try fully qualified imports, e.g. `import javax.swing.JFrame` instead.

---

<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:** [October 26, 2019, 2:28pm UTC](https://forum.inductiveautomation.com/t/accessing-built-in-java-libraries-from-jython-scripts/29417/3 "2019-10-26T14:28:01Z")

</div>

Will try and update you. Thanks a lot

---

<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:** [October 26, 2019, 5:23pm UTC](https://forum.inductiveautomation.com/t/accessing-built-in-java-libraries-from-jython-scripts/29417/4 "2019-10-26T17:23:13Z")

</div>

> [@Kevin.Herron](#):
>
> Try fully qualified imports, e.g. `import javax.swing.JFrame` instead.

No replacing \* in the client script for a button actionPerformed event with following

import javax.swing.JFrame  
import javax.swing.JLabel  
....

also gives same error "NameError: name 'JFrame' is not defined"

---

<div class="post-metadata">

**Author:** ![chi](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@chi](https://forum.inductiveautomation.com/u/chi)\
**Post date:** [October 26, 2019, 5:44pm UTC](https://forum.inductiveautomation.com/t/accessing-built-in-java-libraries-from-jython-scripts/29417/5 "2019-10-26T17:44:34Z")

</div>

Try

```auto
from javax.swing import JFrame

```

---

<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:** [October 26, 2019, 5:56pm UTC](https://forum.inductiveautomation.com/t/accessing-built-in-java-libraries-from-jython-scripts/29417/6 "2019-10-26T17:56:25Z")

</div>

> [@chi](#):
>
> from javax.swing import JFrame

Yesssssss! It works! However the "import javax.swing.JFrame" syntax works from the script playground but not in the script window for a component event or gateway script event! There the syntax "from javax.swing import JFrame" seems to work!

Thanks a lot guys, you have made my day today!

---

<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:** [October 28, 2019, 9:36am UTC](https://forum.inductiveautomation.com/t/accessing-built-in-java-libraries-from-jython-scripts/29417/7 "2019-10-28T09:36:04Z")

</div>

There is just one issue though, the imported java functions like JFrame etc are not accessible from within a function in a gateway event script or a startup script! Should we have to access these functions as a fully qualified name such as project.JFrame etc ? What would the fully qualified path be for these scripts?

---

<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:** [October 28, 2019, 9:57am UTC](https://forum.inductiveautomation.com/t/accessing-built-in-java-libraries-from-jython-scripts/29417/8 "2019-10-28T09:57:07Z")

</div>

The gateway service runs headless. So no, you should not expect to have those available.

---

<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:** [October 28, 2019, 11:06am UTC](https://forum.inductiveautomation.com/t/accessing-built-in-java-libraries-from-jython-scripts/29417/9 "2019-10-28T11:06:20Z")

</div>

But they are accessible from outside a function ! If you mean JFrame (UI related) per say then non UI functions are also behaving the same way , I. e. Accessible outside a function but not from inside !

---

<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:** [October 28, 2019, 6:47pm UTC](https://forum.inductiveautomation.com/t/accessing-built-in-java-libraries-from-jython-scripts/29417/10 "2019-10-28T18:47:31Z")

</div>

> [@prafull\_j](#):
>
> Should we have to access these functions as a fully qualified name such as project.JFrame etc ? What would the fully qualified path be for these scripts?

Yes with fully qualified names to the function call , I am able to access these JAVA functions.
