# The Java Bindings¶

This section describes jMSG, the Java API to Simgrid. This API mimicks MSG, which is a simple yet somehow realistic interface. The full reference documentation is provided at the end of this page.

Most of the documentation of the MSG API in C applies directly to the Java bindings (any divergence is seen as a bug that we should fix). MSG structures are mapped to Java objects as expected, and the MSG functions are methods in these objects.

## Installing the Java bindings¶

The easiest is to use a precompiled jarfile, but some people may prefer to compile it from the sources.

## Using the Java bindings¶

In most cases, you can use the SimGrid bindings as if it was a Java library:

$javac -classpath .:path/to/simgrid.jar your/java/Code.java$ java -classpath .:path/to/simgrid.jar your.java.Code the/parameter/to/your/code


For example:

$cd examples/java$ java -classpath ../../simgrid.jar:. .:../../simgrid.jar app.pingpong.Main ../platforms/platform.xml


Any SimGrid simulation (java or not) is usually constituted of several kind of actors or processes (classes extending @c Msg.Process) that are deployed over the hosts of the virtual platform. So, your code should declare these actors, plus a Main class in charge of deploying your actors on the platform. Please refer to the examples for details.

## Troubleshooting¶

Actually, these bindings are not only implemented in Java. They do use the C implementation of SimGrid. This should be transparent as this library is directly included in the simgrid.jar file but things can still go wrong is several ways.

This means that the JVM fails to load the native library. If you use a precompiled jarfile, please report this bug.

If you built it yourself, you can try to use an installed version of the library instead of the one included in the jar. For that, add the path to the native library into the LD_LIBRARY_PATH variable (or in the DYLD_LIBRARY_PATH on Mac OSX).