# Using an external java class

**URL:** <https://discourse.processing.org/t/using-an-external-java-class/1895>\
**Category:** Development\
**Created:** [July 19, 2018, 6:10am UTC](https://discourse.processing.org/t/using-an-external-java-class/1895 "2018-07-19T06:10:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![colinh](https://avatars.discourse-cdn.com/v4/letter/c/dc4da7/32.png) [@colinh](https://discourse.processing.org/u/colinh)\
**Post date:** [July 19, 2018, 6:10am UTC](https://discourse.processing.org/t/using-an-external-java-class/1895/1 "2018-07-19T06:10:56Z")

</div>

I’ve written a java class (which interfaces to a C library via JNI) and which I’d like to use in a sketch.

```auto
// **** bezier/BezFit.java
package bezier;
public class BezFit {
    static { System.loadLibrary("bezier"); }
    public static native void fitCurve(double[] result, int n, double delta, double[] d);
}

```

and I can use this from java like this:

```auto
// **** Tst.java
import bezier.BezFit;

public class Tst {
    public static void main(String[] args) {
	    double[] data = {0.01, 0.01, 0.3, 1.0, 0.7, 2.0, 1.0, 2.4, 2.0, 3.0, 3.0, 3.6, 3.4, 4.0, 3.8, 5.0, 4.0, 6.0};
	    double[] bez = new double[8];   
	    BezFit.fitCurve(bez, 9, 0.5, data);
	    System.out.println("control pt 1: " + bez[2] + ", " + bez[3]);
	}
}

```

Now, what is the **simplest** way of using BezFit in a single sketch? Do I absolutely have to create a library? I don’t use Eclipse. I use vi and javac 🙂

I had a look at [https://forum.processing.org/two/discussion/21049/creating-a-library](https://forum.processing.org/two/discussion/21049/creating-a-library) where it says: “Firstly - are you clear about how Java works, and what happens in Processing under the hood?”

No, I’m not a java programmer and no, I don’t know what happens under the hood :-/

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [July 19, 2018, 6:32am UTC](https://discourse.processing.org/t/using-an-external-java-class/1895/2 "2018-07-19T06:32:36Z")

</div>

I don’t know much about it but I am interested to help but I not today as I ran out of time. I have some c++ experience but unfortunately not in Windows but in linux. Do you have the jar files for jni? You should provide this jar during the building via the classpath on the command line. You might need extra libraries.

Check these links:

> [using c++ library in processing.org - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/11256/using-c-library-in-processing-org)[adding external library with JNI interface - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/3346/adding-external-library-with-jni-interface)[https://processing.org/discourse/beta/num\_1147602703.html](https://processing.org/discourse/beta/num_1147602703.html)

Kf

---

<div class="post-metadata">

**Author:** ![colinh](https://avatars.discourse-cdn.com/v4/letter/c/dc4da7/32.png) [@colinh](https://discourse.processing.org/u/colinh)\
**Post date:** [July 19, 2018, 6:44am UTC](https://discourse.processing.org/t/using-an-external-java-class/1895/3 "2018-07-19T06:44:25Z")

</div>

> [@](#):
>
> I don’t know much about it but I am interested to help but I not today as I ran out of time.

Thanks for replying.

> [@](#):
>
> I have some c++ experience but unfortunately not in Windows but in linux.

? It’s written in C, not C++. And I’m on linux too…

> [@](#):
>
> Do you have the jar files for jni? You should provide this jar during the building via the classpath on the command line. You might need extra libraries.

I don’t want to use the C library from Processing (and I never want to touch JNI again either…). I want to use the java class.

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [July 19, 2018, 9:21am UTC](https://discourse.processing.org/t/using-an-external-java-class/1895/4 "2018-07-19T09:21:10Z")

</div>

> [@colinh](#):
>
> I don’t want to use the C library from Processing (and I never want to touch JNI again either…).

Processing includes the JNA library. Can’t remember how easy this is to access from a sketch, but it would be a far easier way of interfacing with the native code than raw JNI.

---

<div class="post-metadata">

**Author:** ![colinh](https://avatars.discourse-cdn.com/v4/letter/c/dc4da7/32.png) [@colinh](https://discourse.processing.org/u/colinh)\
**Post date:** [July 19, 2018, 8:08pm UTC](https://discourse.processing.org/t/using-an-external-java-class/1895/5 "2018-07-19T20:08:04Z")

</div>

OK, I ended up installing Netbeans.

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [July 19, 2018, 9:19pm UTC](https://discourse.processing.org/t/using-an-external-java-class/1895/6 "2018-07-19T21:19:51Z")

</div>

> [@colinh](#):
>
> OK, I ended up installing Netbeans.

Well, you can’t go wrong with that choice! 😁
