Solved - How to load external java class?

SOLVED - Wow…so instead of trying to access the class through the bean or a reference, I just called the function needed directly and it worked! No programming needed.

i.e., instead of elements.bean_73.Molecule.toBinFormat() I just used mol.toBinFormat after populating the var mol with a molecule object.

We have some 3rd party java classes/libraries.

I can’t figure out how to reference them in servoy.

Is there a way to load a java class via a method without having to code it into a servoy plugin/bean?

And, if so, once loaded, how do you reference that in servoy?

This is a generic question.

I’m not a java progammer, but we have some existing java classes that we use other places and would like to be able to load and call their function in servoy.

Also, we have a 3rd party bean that loads a class. This class has an API and its functions are available in the bean itself, but we’d like to reference the class API within servoy methods.

Is it possible to reference a beans loaded classes via servoy methods?

Thanks for any help!

NCM
FSCI

The answer is: yes you can but…

The classes you use need to be in the Servoy classpath.

The methods you use will most likely need to be addresses including packagename and classname.

In other words you are going to do Java stuff. That IS a different ballgame and as such something you will need to do some reading about.

IT2B,

As noted above, I did find that I can call any of the functions loaded by beans directly. I was always trying to reference them through the bean element, but that would never work.

Without a bean loading the classes, though:

What would be the proper way to reference something like this?

Would I place the java classes in the lib, bean or plugin folders…and once there call them using the java package/class reference: package.class?

Will the classpath in Servoy need to be to the servers classpath or on each individual clients classpath?

Will the classpath designation load them into servoy, or would I need to load them through a method first?

Some hints on how servoy would treat this situation would be appreciated. When I get to that point, I’ll read up more on the java basics of it.

I’m not opposed to learning more about java…I’ve dug in some, but its not something I have a lot of experience in - mostly DB, SQL, PHP and some other programming languages and utilizing existing java packages and classes.

Thanks for chiming in.

NCM
FSCI

I am afraid I am not the one that can help you out.

I know much about plugins and beans but never reference classes etc direct from Servoy. So maybe somebody else can help you.

Hi FSCI,

Not entirely sure what you’re asking but here goes:

fsciweb:
Would I place the java classes in the lib, bean or plugin folders…and once there call them using the java package/class reference: package.class?
FSCI

If you put the .jar library in the beans or plugins folder, it will be available in the client instance. (Using lib folder will only be available on the server machine… i think)

fsciweb:
Will the classpath in Servoy need to be to the servers classpath or on each individual clients classpath?
FSCI

You won’t have to worry about “classpath” if you use one of those two folders. Perhaps you may be thinking of what is often called “the fully qualified class name” i.e. package.sub_package.Class -quite different from classpath.

fsciweb:
Will the classpath designation load them into servoy, or would I need to load them through a method first?
FSCI

A library is loaded when you first reference the class in your code. You don’t have to ever load a bean in the designer to use the library. You could for example instantiate a bean directly in a javascript method.

The convention for thatis “Packages”.package.class
ex:

var mol = new Packages.sunw.demo.molecule();

…but you have to have a good idea ofthe methods you are calling. Don’t expect things to magically happen for you. The best thing to do is look up the Javadoc of the library you are using. This is the standard HTML-based documentation that most java libraries will ship with.

Hope this helps,
sean

Sean,

Thanks for the pointers.

I have been able to get quite a few of them working, but your comments well help in the future.

Thanks!

NCM
FSCI