0: Download
Go here: Download

1: Configure Matlab
Run Matlab and print:
>> edit classpath.txt
press Enter.

Here you see: classpath.txt. Go to the last line and put the path to the downoaded library, then add (!) empty string:

Save and restart Matlab.

2: How to call
Create new java-project and include downloaded library:

3: Example

To execute matlab function “sum” from java use the next line:

Object[] outputArgs =
matlabClient.executeMatlabFunction("sum",inArgs, 1);


import com.jamal.*;
import com.jamal.client.MatlabClient;

public class Run0 {
	public static void main(String[] args) {
		try {
			MatlabClient matlabClient = new MatlabClient(
					"C:\\Program Files\\MATLAB\\R2010a\\bin\\matlab.exe", 40);

			// First we pass an array of integers and calculate sum in Matlab
			Object[] inArgs = new Object[1];
			inArgs[0] = new int[] { 1, 2, 3, 4 };

			Object[] outputArgs = matlabClient.executeMatlabFunction("sum",
					inArgs, 1);
			double[] result = (double[]) outputArgs[0];
			System.out.println("The sum 1+2+3+4=" + result[0]);


		} catch (JamalException e) {




The matlab will run RMI server and start processing calls from your client. To stop server use the matlabClient.shutDownServer(); line.

Also you can stop the server manually by running jamal.jar and pressing “stop” button:

Good luck in your work.

See project website for more details: http://jamal.khadkevich.org


11 Responses to “Instructions”

  1. 1 pxl October 10, 2011 at 1:06 pm

    Hi, i have a problem, i have done this but cant do it.

    Jamal::Matlab host seems to be dead. Trying to launch MatlabServer on the localhost…
    Jamal::Trying to connect to MatlabServer… 0

    please help me how can solve this problem ?

  2. 2 Fieral October 12, 2011 at 10:52 am

    Can you describe your problem in more detail?

  3. 3 ASHISH April 3, 2012 at 2:33 pm

    Hi, i have a problem, i have done this but cant do it.

    Jamal::Matlab host seems to be dead. Trying to launch MatlabServer on the localhost…
    com.jamal.JamalException: Jamal::Matlab host seems to be dead
    at com.jamal.client.MatlabClient.(MatlabClient.java:85)
    at Run.main(Run.java:14)
    Caused by: java.rmi.ConnectException: Connection refused to host:; nested exception is:
    java.net.ConnectException: Connection refused: connect
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:340)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at java.rmi.Naming.lookup(Naming.java:101)
    at com.jamal.client.MatlabClient.(MatlabClient.java:64)
    … 1 more
    Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at java.net.Socket.(Socket.java:425)
    at java.net.Socket.(Socket.java:208)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:146)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)

  4. 4 hutb April 4, 2012 at 11:15 am

    The stack trace tells that the server part of JAMAL is not running. Try to start Matlab and run the following command in Matlab prompt before calling functions from java:

    If you see the following line you are lucky:
    Jamal::MatlabServer is ready

  5. 5 About Java December 26, 2012 at 1:00 pm

    interesting article.. thanks for sharing.. 🙂

  6. 6 Zouhir February 4, 2013 at 12:11 pm

    how I can stop the server directly from the console matlab?


  7. 7 sara February 23, 2013 at 5:29 pm

    thanks for your help , it is very useful

  8. 8 sara February 23, 2013 at 5:53 pm

    please i want to know if i have my own function in m file on matlab how can i execute it from java

    • 9 Zouhir February 26, 2013 at 3:45 pm

      hi Sara,

      you need to add the library jamal

      I send you a example
      in Java:

      MatlabClient matlabClient = new MatlabClient(MatlabCaller.HOST_ADDRESS,”C:/Program Files/MATLAB/R2011a/bin/matlab.exe”,40);

      /* meto los argumentos de la funcion
      como ejemplo en este caso sin argumentos

      Object [] ArrayInputs = new Object[0];

      /*llamada a la funcion que va a realizar la segmentacion */

      Object [] SalidaFuncion= matlabClient.executeMatlabFunction(“test”,ArrayInputs ,1);



      I hope you serve as a guide

  9. 10 Neha March 7, 2013 at 2:06 pm

    Thanks your instructions helped me learn this. I am eager to know…if I can even run MATLAB simulations and MATLAB 3d animations through Java.

  1. 1 MATLAB | Thermal Vision Research Trackback on May 11, 2012 at 4:37 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: