# Java Mode: How to import external code?

**URL:** <https://discourse.processing.org/t/java-mode-how-to-import-external-code/12258>\
**Category:** Processing\
**Created:** [June 24, 2019, 8:08am UTC](https://discourse.processing.org/t/java-mode-how-to-import-external-code/12258 "2019-06-24T08:08:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LoliProcessor](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@LoliProcessor](https://discourse.processing.org/u/LoliProcessor)\
**Post date:** [June 24, 2019, 8:08am UTC](https://discourse.processing.org/t/java-mode-how-to-import-external-code/12258/1 "2019-06-24T08:08:05Z")

</div>

I have never imported a library in my life before.  
Google says compile it including it to the classpath.  
So how do include external java code that I want to use in my sketch but isnt in the sketch’s directory?  
And what format does it have to be in?  
plain directory, jar?  
probably compiled code (.class) ?

How do I reference a library WITHOUT having to COPY it to the SKETCH DIRECTORY?

---

<div class="post-metadata">

**Author:** ![figraham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/figraham/32/4161_2.png) [@figraham](https://discourse.processing.org/u/figraham)\
**Post date:** [June 24, 2019, 8:49am UTC](https://discourse.processing.org/t/java-mode-how-to-import-external-code/12258/2 "2019-06-24T08:49:25Z")

</div>

If the [library is one specifically for processing](https://processing.org/reference/libraries/) then just go to sketch\>import library…\>add library… in the Processing IDE.

If it’s a external java library check out [Dan Shiffman’s coding challenge](https://thecodingtrain.com/CodingChallenges/137-4d-opensimplex-noise-loop.html) where he uses OpenSimplex.java in the challenge. If I remember right you can add a .java file your sketch. I haven’t used the Processing IDE in a while so I’m not entirely sure on this one.

If you’re using processing in eclipse you import the .jar and add it to the build path. You can also check out [Dan’s latest live stream](https://www.youtube.com/watch?v=rnJgb-mYPEI) (around time code 1:08:30) where he started working on porting a java library to processing. The procedure in eclipse is the exact same as when he imports core.jar.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [June 24, 2019, 9:19am UTC](https://discourse.processing.org/t/java-mode-how-to-import-external-code/12258/3 "2019-06-24T09:19:39Z")

</div>

We can drag & drop “.java” & “.jar” files into the PDE. ☕

---

<div class="post-metadata">

**Author:** ![LoliProcessor](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@LoliProcessor](https://discourse.processing.org/u/LoliProcessor)\
**Post date:** [June 24, 2019, 11:21am UTC](https://discourse.processing.org/t/java-mode-how-to-import-external-code/12258/4 "2019-06-24T11:21:56Z")

</div>

I guess I meant it rather like that it doesn’t copy the files everytime but just silently knows the path to where to look namespaces up.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [June 24, 2019, 11:05pm UTC](https://discourse.processing.org/t/java-mode-how-to-import-external-code/12258/5 "2019-06-24T23:05:49Z")

</div>

> [@LoliProcessor](#):
>
> How do I reference a library WITHOUT having to COPY it to the SKETCH DIRECTORY?

There’s no clear way to specify an arbitrary path where the PDE (Processing’s IDE) can find libraries AFAIK. 😢

It’s either inside our sketch’s folder or inside sketchbook’s libraries folder. 😐

The wiki below teaches how to manually install libraries for the PDE though: 👼

- [How to Install a Contributed Library · processing/processing Wiki · GitHub](http://GitHub.com/processing/processing/wiki/How-to-Install-a-Contributed-Library)

---

<div class="post-metadata">

**Author:** ![LoliProcessor](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@LoliProcessor](https://discourse.processing.org/u/LoliProcessor)\
**Post date:** [June 25, 2019, 10:41pm UTC](https://discourse.processing.org/t/java-mode-how-to-import-external-code/12258/6 "2019-06-25T22:41:57Z")

</div>

I guess that works too, since most of my projects are using processing rn anyway 😃

Can I just copy my libraries into the library folder?

Which format do they have to be in:  
.jar, .class or.java?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [June 25, 2019, 10:53pm UTC](https://discourse.processing.org/t/java-mode-how-to-import-external-code/12258/7 "2019-06-25T22:53:40Z")

</div>

> [@Including shared pde files across projects](https://discourse.processing.org/t/including-shared-pde-files-across-projects/1701/20):
>
> Not according to the article for installing libraries in Processing: no_entry[https://GitHub.com/processing/processing/wiki/How-to-Install-a-Contributed-Library](https://GitHub.com/processing/processing/wiki/How-to-Install-a-Contributed-Library) The top folder of a library must have the same name as the .jar file located inside a library’s library folder (minus the .jar extension): Therefore, we’re free to choose whatever name to the “.jar” file, as long as we use that same name for its top folder. face_with_monocle My “.jar” file was named as: “Palette.jar”. So in o…
