Accessing built-in JAVA libraries from jython scripts

scripting
#1

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?

0 Likes

#2

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

#3

Will try and update you. Thanks a lot

0 Likes

#4

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”

0 Likes

#5

Try

from javax.swing import JFrame
1 Like

#6

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!

0 Likes

#7

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?

0 Likes

#8

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

1 Like

#9

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 !

0 Likes

#10

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

0 Likes