I have been testing the use of an external java package within Ignition. I know it is importing via sys.add_package so it is being seen by the system. However I am calling the constructor in the pythonesque way (due to jython) and I am getting errors where it says “expected 0 args, got 2”. Well the constructor requires at least 2, so I am not sure where to focus the investigation.
Since this is a pretty flat package, I am just using “from MyPackage import *” which seems to be working as I am not getting any class-not-found exceptions.
This aside, following some guidance from another party, I created a dummy module to wrap this jar so that Ignition would be able to push it to clients. Or so is my hope. I have successfully imported it into the gateway and have the scope set to ‘GCD’. However I was unable to access anything I am mentioning above without hand-inserting the jar into /usr/local/igntion/lib/core/… Shouldn’t have Ignition pushed that jar out? I did restart the gateway and re-login to my designer.
Ok, after more head-banging on this, and countless poking through Google searches, I am stuck. I am now getting a little further, but getting an error that I just cannot diagnose…
So in a script, I call ‘import myJavaPackage’. This is effectively the jar, which contains all the related classes. It is flat, there is no hierarchy, so this import should (and appears to) pull in all the classes of the package. A good thing.
From there, I did a call to a static function in one of the classes. This worked fine and I got a valid return value, etc.
Then I moved on to another class where I ran into my hurdle… The constructor requires two parameters as noted in my first post in this thread. Now I have gotten past the earlier error as I am calling “my class = myJavaPackage.myClassConstructor(arg1, arg2)”. When I hit that line, I get an error “TypeError: cannot create ‘myJavaPackage.myClassConstructor’ instances”. Looking at anything involving the instantiation of an object in python it appears I am doing it correctly. Note that my args are definitely of the right type. I even tried casting them just to be safe (they are ints) and that made no difference.
I know this might be getting more into a language issue than an Ignition issue, but this works outside of Ignition, so hence I am vexed as to why this error is coming up or even what it means. I am hoping someone has seen such an issue and can explain what I can try to resolve this… Thanks in advance!
[quote=“jjcampbell76”]Ok, after more head-banging on this, and countless poking through Google searches, I am stuck. I am now getting a little further, but getting an error that I just cannot diagnose…
So in a script, I call ‘import myJavaPackage’. This is effectively the jar, which contains all the related classes. It is flat, there is no hierarchy, so this import should (and appears to) pull in all the classes of the package. A good thing.
From there, I did a call to a static function in one of the classes. This worked fine and I got a valid return value, etc.
Then I moved on to another class where I ran into my hurdle… The constructor requires two parameters as noted in my first post in this thread. Now I have gotten past the earlier error as I am calling “my class = myJavaPackage.myClassConstructor(arg1, arg2)”. When I hit that line, I get an error “TypeError: cannot create ‘myJavaPackage.myClassConstructor’ instances”. Looking at anything involving the instantiation of an object in python it appears I am doing it correctly. Note that my args are definitely of the right type. I even tried casting them just to be safe (they are ints) and that made no difference.
I know this might be getting more into a language issue than an Ignition issue, but this works outside of Ignition, so hence I am vexed as to why this error is coming up or even what it means. I am hoping someone has seen such an issue and can explain what I can try to resolve this… Thanks in advance![/quote]
PM Me and we can do a remote session, and we can post the fix once we figure it out.
Ok, this got resolved. Ended up being a situation where the package in question required two additional support packages. Specifically JSP-related jars. The reasoning being that jython acts differently than desktop java where it must preflight the classes and such. Therefore when it could not fully resolve the JSP classes referenced, it errored. Since I was not making use any JSP stuff in the package, it was not making sinking in as to the root cause.
I ended up rolling the desired package along with the two support packages into a module wrapper. With these jars referenced, Ignition put it on the appropriate class path and thus I was able to access the classes from within my scripts. I did need to do a ‘sys.add_package(“myPackage”)’ call followed my an ‘import myPackage’ call to pull it in.