# Does Processing support packages?

**URL:** <https://discourse.processing.org/t/does-processing-support-packages/6585>\
**Category:** Processing\
**Created:** [December 14, 2018, 2:17am UTC](https://discourse.processing.org/t/does-processing-support-packages/6585 "2018-12-14T02:17:49Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![MCCreeper8890](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mccreeper8890/32/751_2.png) [@MCCreeper8890](https://discourse.processing.org/u/MCCreeper8890)\
**Post date:** [December 14, 2018, 2:17am UTC](https://discourse.processing.org/t/does-processing-support-packages/6585/1 "2018-12-14T02:17:50Z")

</div>

I’m creating a physics simulator, and I want the “force” classes to be arranged in a class called `force`. I noticed Processing still has `public` `private` and `package`. However, I suspect these are from Java itself, and are not implemented in Processing `.pde` files. But I remain hopeful.

Does Processing actually support `package`?

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [December 14, 2018, 2:24am UTC](https://discourse.processing.org/t/does-processing-support-packages/6585/2 "2018-12-14T02:24:24Z")

</div>

No, I don’t think the Processing editor supports packages in the way you’re describing.

You could use Processing as a Java library:

> **[Processing in Java](https://happycoding.io/tutorials/java/processing-in-java)**
>
> Learn how to use Processing as a Java library.

And then you could use packages. You could even export your code as a library and import that library back into the Processing editor if you wanted to.

---

<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:** [December 14, 2018, 3:07am UTC](https://discourse.processing.org/t/does-processing-support-packages/6585/3 "2018-12-14T03:07:41Z")

</div>

- We can mix “.pde” w/ “.java” files together in the same sketch project folder. ☕
- We can optionally use keyword `package` inside “.java” files. 📦
- And then optionally use keyword `import` inside “.pde” files in order to access classes and interfaces inside those “.java” files. 📂
- Take a look at these 2 sketch links containing both “.pde” & “.java” files on them: 😸

> <https://gist.github.com/GoToLoop/ea4db8a8622e27541213da3c9a43ca21>

  

> <https://gist.github.com/GoToLoop/bba0c288aaeeb5ef9bb1>

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [December 14, 2018, 5:57pm UTC](https://discourse.processing.org/t/does-processing-support-packages/6585/4 "2018-12-14T17:57:56Z")

</div>

@GoToLoop How are you creating those `.java` files? When I try adding a package statement inside a `.java` tab in the Processing editor, I get an error.

---

<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:** [December 14, 2018, 6:10pm UTC](https://discourse.processing.org/t/does-processing-support-packages/6585/5 "2018-12-14T18:10:15Z")

</div>

It’s relatively recent that PDE allows keyword `package` inside “.java” files.  
I’ve forgotten the exact version it was though.  
However, even “.java” files can’t use any new Java 8 features yet.

---

<div class="post-metadata">

**Author:** ![David](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/david/32/8853_2.png) [@David](https://discourse.processing.org/u/David)\
**Post date:** [May 18, 2020, 1:48pm UTC](https://discourse.processing.org/t/does-processing-support-packages/6585/6 "2020-05-18T13:48:20Z")

</div>

Hi! I’m working on a project in which I want to incorporate some Java code. Since I’ve never done this before, I googled for examples and found yours. So I copy/pasted your code, but when I tried to run it, I got the following error:

```auto
No library found for gotoloop.countdown
The import gotoloop.countdown.Countdown conflicts with a type defined in the same file

```

I’m running Processing v3.5.4 under Windows 7, sp1. I wasn’t sure whether you needed to compile the Java code outside of Processing first, or whether Processing would take care of that for you, so I tried it both ways, with the same result. I compiled the Java code under Java v14.0.1.

Any idea what I’m doing wrong?

Thanks.

---

<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:** [May 18, 2020, 5:34pm UTC](https://discourse.processing.org/t/does-processing-support-packages/6585/7 "2020-05-18T17:34:24Z")

</div>

> [@David](#):
>
> I compiled the Java code under Java v14.0.1.

That’ll surely fail b/c P3 can’t use anything compiled after Java 8!

We’re gonna have to await for the P4 version.

'Til then you’re gonna need to pass some commands to Java 14 so it outputs Java 8 compiled code.

P.S.: We don’t need to compile “.java” files & package them as “.jar” files before using them on the PDE.

> [@David](#):
>
> The import gotoloop.countdown.Countdown conflicts with a type defined in the same file

Make sure you don’t have any `class` or `interface` named Countdown somewhere else besides “Countdown.java” file.

Make sure you don’t have any “.pde” file named “Countdown.pde”.

---

<div class="post-metadata">

**Author:** ![David](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/david/32/8853_2.png) [@David](https://discourse.processing.org/u/David)\
**Post date:** [May 18, 2020, 7:47pm UTC](https://discourse.processing.org/t/does-processing-support-packages/6585/8 "2020-05-18T19:47:20Z")

</div>

Thanks. I finally got it to work after I removed the “import” statement from the Processing file and the “package” statement from the Java file.

---

<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:** [May 18, 2020, 8:48pm UTC](https://discourse.processing.org/t/does-processing-support-packages/6585/9 "2020-05-18T20:48:33Z")

</div>

> [@David](#):
>
> I finally got it to work after I removed the `import` statement from the Processing file and the `package` statement from the Java file.

That’s strange… Ru sure the Java file is actually using the extension “.java”: ❓  
“Countdown.java”

Glad your workaround worked as well. But it’s probably b/c the `class` Countdown is inside a “.pde” file instead of a “.java” 1. ☕

---

<div class="post-metadata">

**Author:** ![David](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/david/32/8853_2.png) [@David](https://discourse.processing.org/u/David)\
**Post date:** [May 18, 2020, 8:55pm UTC](https://discourse.processing.org/t/does-processing-support-packages/6585/10 "2020-05-18T20:55:23Z")

</div>

No, the Java file was named “Countdown.java” and the Processing file was named “JavaExample.pde”.

---

<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:** [May 18, 2020, 9:12pm UTC](https://discourse.processing.org/t/does-processing-support-packages/6585/11 "2020-05-18T21:12:21Z")

</div>

Just to make sure, I’ve copied & pasted the contents of the file [“CountdownClass.pde”](https://gist.githubusercontent.com/GoToLoop/ea4db8a8622e27541213da3c9a43ca21/raw/d1a2d017af0b5aa142257f58270f42d29d7d3b7c/CountdownClass.pde) onto the main tab of the PDE.

Then created a “New Tab” (CTRL + SHIFT + N) typing in this exact name Countdown.java on the popup.

Again copied & pasted the contents of the file [“Countdown.java”](https://gist.githubusercontent.com/GoToLoop/ea4db8a8622e27541213da3c9a43ca21/raw/d1a2d017af0b5aa142257f58270f42d29d7d3b7c/Countdown.java) on that new Java tab.

Hit “Run” (CTRL + R) and they compiled & run on the PDE.

64-bit PDE v3.5.4 on Win 8.1 AMD laptop here.

---

<div class="post-metadata">

**Author:** ![David](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/david/32/8853_2.png) [@David](https://discourse.processing.org/u/David)\
**Post date:** [May 18, 2020, 9:48pm UTC](https://discourse.processing.org/t/does-processing-support-packages/6585/12 "2020-05-18T21:48:39Z")

</div>

I tried it again, following your steps exactly, and this time it ran, although I still see an error message in red in the console:

```auto
No library found for gotoloop.countdown
323 7823 7500 Delay: 7500 - Done: false

```

If I remove the import statement, I get this error and the sketch doesn’t run.

`Cannot find a class or type named “Countdown”`

And finally, if I also remove the package statement, it runs without any error.

Maybe there’s something different in my setup, but I don’t know what. I’m running Processing 3.5.4 (64-bit) on Windows 7. But I don’t think that would make any difference.

---

<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:** [May 18, 2020, 9:54pm UTC](https://discourse.processing.org/t/does-processing-support-packages/6585/13 "2020-05-18T21:54:23Z")

</div>

> [@David](#):
>
> `No library found for gotoloop.countdown`

This is some weird glitch on the PDE. Seems like it doesn’t like `package` declarations. 🥴
