I have some libraries written in java how to use that java functions in python-robotframework
Multiple options.
Option 1:
Use the jrobotremoteserver to serve a Keyword Library (written in Java) to Robot Framework
You can find some Java Library example snippets only in the older User Guides , since Java was no longer supported with Robot Framework 5 (as Python2/Jython was no longer supported).
But serving such libraries via jrobotremoteserver would still be possible.
Option 2:
Use JPype
If you want to use Java (e.g. to develop a Keyword Library) I recommend to look into JPype.
However, if I understand correctly you would still need to compile and package that file in a .jar.
An example. It’s just a calculator in java and the methods are called from Robot
JavaWrapper.py
# Boiler plate stuff to start the module
import jpype
import jpype.imports
from jpype.types import *
from inspect import getmembers, isfunction
# Launch the JVM
jpype.startJVM(classpath=['library/exercise/solution/JavaLibrary.jar'])
from org.calculator import JavaLibrary
class JavaWrapper:
def get_keyword_names(self):
for name, func in getmembers(JavaLibrary, isfunction):
if name.startswith('_'):
continue
yield name
def run_keyword(self, name, args, kwargs):
print("Running keyword '%s' with positional arguments %s and named arguments %s."
% (name, args, kwargs))
func = getattr(JavaLibrary, name)
return func(*args, **kwargs)
JavaLibrary.java
package org.calculator;
/*
* A class which provides functions for all basic arithmetic operations
* add, subtract, multiply, divide, and remainder.
*/
public class JavaLibrary {
public static int add(int a, int b) {
return a + b;
}
public static int subtract(int a, int b) {
return a - b;
}
public static int multiply(int a, int b) {
return a * b;
}
public static int divide(int a, int b) {
return a / b;
}
public static int remainder(int a, int b) {
return a % b;
}
}
test.robot
*** Settings ***
Library JavaWrapper.py
*** Test Cases ***
Use Dynamic Library
${result} Add ${1} ${2}
Log ${result}
${result} Subtract ${3} ${1}
Log ${result}