Understanding Classpaths when creating externals in Eclipse w toxi Libs


    Jan 11 2014 | 8:41 am
    Hey,
    I am relatively inexperienced Java person, I usually work with Processing and avoid Eclipse, but I have created a few max externals previously. I haven't, however, created any mxj objects that use external libraries.
    I thought I followed the process correctly. I believe I have imported the libraries correctly into my java project in eclipse (toxi libs). I am not getting any errors, put it that way, but when I try and run the object in max I get this error.
    java.lang.NoClassDefFoundError: toxi/physics2d/behaviors/ParticleBehavior2D
    I believe this is a class path thing? Perhaps max doesn't know where to find the verletphysics.jar ?
    My class is below. Essentially I am wanting to use toxi physics to augment imput - at the present it is obviously not doing that - I was just testing the concept , which didn't work!! The class is based on Toxi's example.
    Any help much appreciated.
    import com.cycling74.max.*;
    import toxi.geom.*; import toxi.physics2d.*; import toxi.physics2d.behaviors.*;
    public class toxiPart extends MaxObject {
    int NUM_PARTICLES = 1;
    VerletPhysics2D physics; AttractionBehavior mouseAttractor; Vec2D mousePos;
    public toxiPart(){
    physics = new VerletPhysics2D(); physics.setDrag(0.05f); physics.setWorldBounds(new Rect(0, 0, 200, 200));
    //set attractor mousePos = new Vec2D(100, 100); // create a new positive attraction force field around the mouse position (radius=250px) mouseAttractor = new AttractionBehavior(mousePos, 1000, 0.9f); physics.addBehavior(mouseAttractor);
    declareInlets(new int[]{ DataTypes.ALL, DataTypes.ALL}); declareOutlets(new int[]{ DataTypes.ALL, DataTypes.ALL});
    }
    void addParticle() { VerletParticle2D p = new VerletParticle2D(Vec2D.randomVector().scale(5).addSelf(200 / 2, 0)); physics.addParticle(p); // add a negative attraction force field around the new particle //physics.addBehavior(new AttractionBehavior(p, 20, -1.2f, 0.01f)); }
    public void bang(){
    if (physics.particles.size() < NUM_PARTICLES) { addParticle(); }
    mousePos.set((float)Math.random()*200, (float)Math.random()*200); physics.update();
    for (VerletParticle2D p : physics.particles) { outlet(0,p.x); outlet(1,p.y); }
    }
    }

    • Jan 11 2014 | 5:17 pm
      You need to place verletphysics.jar into the Max classpath. On the Mac I believe this would be anywhere in the Max path - I put mine in "/Applications/Max 6.1/Cycling '74/java/lib".
    • Jan 11 2014 | 7:18 pm
      Also if you want to create easily redistributable library of Java objects, your can build a jar-file with all dependencies in it and place this file to the "Cycling '74/java/lib" directory.
    • Jan 13 2014 | 5:55 am
      Awesome, thanks for the replies - will get onto that tonight!
      Tim