# How to integrate 2 languages using python robotframework

**URL:** <https://forum.robotframework.org/t/how-to-integrate-2-languages-using-python-robotframework/5234>\
**Category:** Libraries\
**Created:** [31 January 2023 09:24 UTC](https://forum.robotframework.org/t/how-to-integrate-2-languages-using-python-robotframework/5234 "2023-01-31T09:24:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harsha](https://avatars.discourse-cdn.com/v4/letter/h/e274bd/32.png) [@Harsha](https://forum.robotframework.org/u/Harsha)\
**Post date:** [31 January 2023 09:24 UTC](https://forum.robotframework.org/t/how-to-integrate-2-languages-using-python-robotframework/5234/1 "2023-01-31T09:24:11Z")

</div>

I have some libraries written in java how to use that java functions in python-robotframework

---

<div class="post-metadata">

**Author:** ![Many](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/many/32/658_2.png) [@Many](https://forum.robotframework.org/u/Many)\
**Post date:** [10 February 2023 11:18 UTC](https://forum.robotframework.org/t/how-to-integrate-2-languages-using-python-robotframework/5234/2 "2023-02-10T11:18:06Z")

</div>

Multiple options.

Option 1:  
Use the [jrobotremoteserver](https://github.com/robotframework/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](https://robotframework.org/robotframework/4.1.3/RobotFrameworkUserGuide.html#creating-test-library-class-or-module) , 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](https://jpype.readthedocs.io/en/latest/)

If you want to use Java (e.g. to develop a Keyword Library) I recommend to look into [JPype](https://jpype.readthedocs.io/en/latest/).

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}

```
