Accessing built-in JAVA libraries from jython scripts

Importing packages in client/gateway scripts with commands like

from javax.swing import *
from 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?

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

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

2 Likes

Will try and update you. Thanks a lot

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"

Try

from javax.swing import JFrame
1 Like

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!

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?

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

1 Like

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 !

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