Java Processing

Not sure of how do you want it to work in your case, or if @GoToLoop already answered what you needed to know.

You could compile your .java files from Idea, exporting a jar file that you can use from the Processing IDE.

It can also be done like this.

  1. I write two sample java files:
// mylib/src/Bar.java
package com.hamoid;
public class Bar {
  public static int sumUp(int a, int b) {
    int i = a + b + 100;
    return i;
  }
}

// mylib/src/Sum.java
package com.hamoid;
public class Sum {
  public static int sumUp(int a, int b) {
    int i = a + b;
    return i;
  }
}
  1. In the terminal, go into that folder cd mylib

  2. Compile the java files into class files: javac -bootclasspath /usr/lib/jvm/default/jre/lib/rt.jar -source 1.6 -target 1.6 -d . -classpath /usr/share/processing/core/library/core.jar src/*.java
    There are two paths to figure out there: one is the path to rt.jar which varies depending on your OS. The other one you may need is the path to Processing’s core.jar but that’s only if your java files make use of PApplet or other Processing classes. If not you can remove -classpath....core.jar.

  3. Pack the the class files into a jar file: jar -cf all.jar com/
    I used com/ because that’s the folder that was created in step 3, since my two java files are inside package com.hamoid.

  4. Then I create a Processing sketch with these files:

    Test.pde
    code/all.jar

The content of Test.pde is this:

import com.hamoid.*;

println(Sum.sumUp(2, 5));
println(Bar.sumUp(2, 5));
  1. Remember to put all.jar inside the code/ folder in the sketch.

If I run it it prints this:

7
107

I hope this helps you a bit in your quest :slight_smile:

1 Like