Java Programming

Last update: Edit

1 Introduction

With Java actions, you can extend the functionality of your application in situations where it would be hard to implement this functionality in microflows.

For information about Java actions in Studio Pro, see Java Actions.

2 Writing Code in .java Files of Your Java Actions

In .java files of your Java actions, the method executeAction is called by the Mendix Runtime when the Java action is being executed. The method throws all exceptions that occur. This means you can do error handling in the microflow calling this Java action. If you would like to do your own error handling within the action, use try / catch statements.

Between the lines // BEGIN USER CODE and // END USER CODE, you can write custom code that will always be called when executing the action. You can call other methods in the section between // BEGIN EXTRA CODE and // END EXTRA CODE.

Code outside the blocks is regenerated each time when you deploy your model, thus any modifications that you make in them will be overwritten. However, your imports will be preserved.

// This file was generated by Mendix Studio Pro.
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the app.
// Special characters, e.g., é, ö, à, etc. are supported in comments.

package myfirstmodule.actions;

import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;

public class JavaAction_1 extends CustomJavaAction<java.lang.Void>
	public JavaAction_1(IContext context)
	public java.lang.Void executeAction() throws Exception
		return true;
	 * Returns a string representation of this action
	public java.lang.String toString()
		return "JavaAction_1";


3 Using the Mendix Java Library

You can use the Mendix Java library in the Java code that you write for your Java actions.

This library is automatically added to your libraries when you import your app into Eclipse, it is called mxruntime.jar.

For details on usage and examples, see How to Use the Java API.

4 Opening HTTP Connections

Most cloud infrastructure services (including those used by the Mendix Cloud) will close HTTP connections automatically if there is no traffic for a few minutes, even if your activity is still waiting for a response. This means that, if your activity calls a web service which takes a long time to respond, the connection may be closed without the activity being aware of this and your activity will not receive a response, but instead get stuck waiting indefinitely for data to arrive.

You should therefore ensure that you always set a timeout for any connections you make in your custom Java code.

5 Using Eclipse as an Environment to Write Your Mendix Java Actions

For details on this topic, see Using Eclipse.

6 Main Documents in This Category

  • Troubleshooting – presents problematic JAR files and workarounds
  • Using Eclipse – describes how to use Eclipse to write and debug the Java actions in your Mendix app