Creating a basic module just to add a java class

I’m trying to add a jar file to ignition so that i can use it in scripting. I don’t have experience at all in this area, but i was able to download the examples from github and to create a module from that in Eclips IDE. but how can i add the jar file to the example project so that i can be able to call it later in ignition. i have a jposservice.jar and i want to be able to use in scripting

import java
import jpos

What do i need to do to be able to add that to the project and create a module?

This won’t work the way you’re hoping.

You can either add scripting functions that use files in the JAR, by following the scripting-function example, or you can skip the module all together and go a somewhat unsupported route where you place the JAR file(s) in $IGNITION/lib/core/gateway or $IGNITION/lib/core/common depending on what scopes you would need to access them.

If you only need a limited number of classes from the jar, you can construct a “script” module that has static public fields containing those classes, and mount it in the system. namespace. You’d have something like this as StaticClasses.java:

import jpos.some.path.to.package.SomeClass;

static public Class<?> SomeClass = SomeClass.class;

In your module hooks’ initializeScriptManager() methods, you’d have:

		manager.addScriptModule("system.jpos", StaticClasses.class, someDocProvider...);

Then you can instantiate SomeClass as system.jpos.SomeClass(...). No import required.

If you need to load a lot of classes, take a look at the solution I used load packages for my Orekit module (with the big disclaimer that this definitely doesn’t fall under proper use of the SDK).

ExtendedScriptManager extendedManager = new ClientExtendedScriptManager(manager);
extendedManager.addScriptPackage(
                new ScriptPackage.ScriptPackageBuilder()
                        .packagePath("org.orekit")
                        .blacklist(Collections.singletonList("org.orekit.compiler.plugin.DefaultDataContextPlugin"))
                        .classLoader(this.getClass().getClassLoader())
                        .build(),
                "system.orekit");

1 Like

thank you all. i will check all this out and try to see if my basic knowledge is enough to use this.