How to use Java w/ Eclipse & Max6 ?

Aug 11, 2012 - 22:35

Because I had some difficulties several years ago (and sometimes, I still have considering new features like project management in Max6 that works fine but can confuse our vision of toolchain,.. sometimes I wrote), I decided to take my keyboard to write this for you.

Here is a small step by step to setup the whole stuff.
I consider you already installed Max6 on your computer.

1/ Installing Eclipse
Download the Eclipse IDE for Java Developers package here
Install it where you want on your computer. It isn’t that important because Eclipse is a all-in-one-folder framework, everything is included in one folder you can move here or there even if, as we’ll see, PATH variables have to be constant if you want to avoid some painful job.

2/ Starting Eclipse the first time
It asks (politely) where you want to put all your future projects files, that is called workspace.
Choose “use this as default and don’t ask again” if you’ll use


eclipse ONLY for this purpose.
I’d suggest you to create a couple of workspaces for different eclipse use..
Here, I’m creating a workspace in a folder named _maxWorkspace (you’ll see why below)

3/ Setting up the beast
I’d suggest to close the welcome screen.
Open a new Java Perspective by going to Window > Open Perspective > Java.
Add the file browser by going to Window > Show View > Navigator

I’d suggest you to close all unuseful panes on the screen to save space like the Task List & the Outline tabs.

4/ Creating your first Java Project
Right click over the Navigator tab, choose New > Java Project.
You can enter the name you want, here I’m choosing maxTest.
It creates a folder name maxTest in the Navigator Pane.

6/ Adding the Max library
Because your Java will have to be related to the Max API, you have to add the max.jar file.
Create a new folder named lib by a right click on the maxTest folder and choose New > Folder
Grab your file in (max installation)/Cycling ’74/java/lib/max.jar and copy/paste it in your freshly created lib folder.

If you have done that in the Finder/Explorer, you have to right click on maxTest folder and choose Refresh to see it.
Again, right click on maxTest and choose Properties > Java Build Path > Libraries > Add JARs and … select the max.jar and click on OK.

You’ll have to add all required new libraries on the same way as the one we just followed.

5/ Setting up the famous Max’s java classpath
Hold on!
This is a very important step.
You’ll have to modify a file very important and I’d suggest you to be careful to not to mess up everything!

Open  the file (max installation)/Cycling ’74/java/

Copy paste the line ; max.dynamic.class.dir /Users/topher/myclasses ;
And modify it according to your workspace, for me it is :
max.dynamic.class.dir /Users/julien/DATA/DEV/_maxWorkspace/maxTest/bin/ ;

Indeed, here, I tell to Max to dynamically load class files in that folder.
Of course, if I want to use eclipse for processing development, I don’t want Max to load any processing classes because I made a mistake or messed some folders at the same workspace root.
This is why I’m using every time different workspaces. It is safer.

This file is processed at each Max startup so, to apply the modifications, you have to restart Max.

7/ Creating a first source file
Right click on the src folder in your Navigator pane in Eclipse, and choose New > Class.
Enter a nice name like helloWorld and paste the following code in that new file:

import com.cycling74.max.*;

public class helloWorld extends MaxObject {

public void bang() {
outlet(0, “Hello human, I’m your first java code inside Max6 !”);

You can go to Source > Correct Indentation to format it correctly like that :


To be sure to have your file built (compiled) at each save , which is very handy, check the project menu about the Build Automatically that should be enabled.

Then save your file.
Something should appear inside the bin folder

8/ Create a patch

Create a new patch in Max (Ctrl N or Cmd N)
Copy-Paste this compressed code:

<pre><code> ———-begin_max5_patcher———- 423.3ocsTsrTCBCEcM7UDyF2Pc.ZKSq6bmtv0tv53DfzRXfDljPkZm9uad.8 g15fs0Mj4dxgy8w4BqccfwrFr.BtG7JvwYsqiiARC3zF6.KQMIEHggFrDKDn EXnm8NItQZvmAeDWTv.Y0kHpG3oaKAqX0bvbBWHA4nkHPBKECHTAQc7LpIBb yLXmNz5RBs.KMIIrEbNiJEjOwZrfv672wkUK6HGzhZgjqpv11ABAusmNTTo4 B3CbBpnKsUHYRFgt3cNNQZeugSTIRkNe8Q3jHSjBaqZjTiNr37AQPMzFWW8C udNAo3OTu6OFfUbBUBlyYkCJaxO5bI3uLW7Oml21simZN7si.+i26iNmdOtV JYzes45o6FinK14vmzGm10BmtQFdEMQkyAxzeG7BiWjd4lX3IWt8tvE7QS5g GGr+nwP.VPne+GFlbnwObdITe9mzUuV07.6RSJVHITjjn1G1wIRwIXKmLRZJ lt+1bJQfhKvlRz+n910rZFc.m+ypYXOplfyrZrFGppZIlKZkzTHpU5bFWGF4 YBITanQQHGujzwerqVsMteQ9PDW4 ———–end_max5_patcher———– </code></pre>

Then, bang the mxj by clicking on the button
Here are the results:



if you modify the source code and save it, even if the compiled file produced is a new one, Max doesn’t know about that fact !
You have to instantiate again the java object

Best practice: you select it, you delete it, then you undo the action… it reinstantiates the new compiled stuff !

10/ Time to read further
I’d suggest you to read (max installation)/Cycling ’74/java-doc/WritingMaxExternalsInJava.pdf
This document hasn’t changed since several years, but it is totally complete.
It explains a lot of the logics behind the Java implementation in Max and deserves to be read right now :)

Something you have to read to and that isn’t really visible at the first time is :
– root of the docs about Java Max API : (max installation)/Cycling ’74/java-doc/api/index.html
– root of the docs about Java Jitter API : (max installation)/Cycling ’74/java-doc/api-jitter/index.html
– Basic tutorials : (max installation)/Cycling ’74/java-doc/tutorial/html/index.html

If you have any questions, you can ask here.
I’ll do my best to answer and unlock you directly in comments here!

You also know I’m providing courses about Max6 and I know well Java.. so :)

No Comments