# Importing Java libraries into embed Processing sketch online

**URL:** <https://discourse.processing.org/t/importing-java-libraries-into-embed-processing-sketch-online/39693>\
**Category:** Libraries\
**Created:** [November 13, 2022, 5:28pm UTC](https://discourse.processing.org/t/importing-java-libraries-into-embed-processing-sketch-online/39693 "2022-11-13T17:28:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zellwd](https://avatars.discourse-cdn.com/v4/letter/z/dbc845/32.png) [@zellwd](https://discourse.processing.org/u/zellwd)\
**Post date:** [November 13, 2022, 5:28pm UTC](https://discourse.processing.org/t/importing-java-libraries-into-embed-processing-sketch-online/39693/1 "2022-11-13T17:28:37Z")

</div>

Hello, I’m trying to embed a Processing sketch onto an HTML page, which uses Java libraries, I’ve been following [this guide](https://cs.nyu.edu/~kapp/cs101/processing_on_the_web).  
Processing on the web does not support imported libraries, which is probably why the program works perfectly on the IDE but not on my webpage. How do I manually add these libraries to my code? Can I just download them and put them in folders somehow?

This is the part of my code that needs to be replaced:

```auto
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

```

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [November 19, 2022, 3:02pm UTC](https://discourse.processing.org/t/importing-java-libraries-into-embed-processing-sketch-online/39693/2 "2022-11-19T15:02:50Z")

</div>

Hi @zellwd,

You can’t do it that way on client-side js. The libraries are for java not for Javascript which processingJS is build for.  
Further, ProcessingJS is outdated, therefore you should use p5js.  
You should adapt the java code to Javascript code. Not all thing from java are possible in js but most.  
If you provide the java code, resp. processing java sketch you want to convert to js, we could try to help you …

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![zellwd](https://avatars.discourse-cdn.com/v4/letter/z/dbc845/32.png) [@zellwd](https://discourse.processing.org/u/zellwd)\
**Post date:** [November 21, 2022, 5:19pm UTC](https://discourse.processing.org/t/importing-java-libraries-into-embed-processing-sketch-online/39693/3 "2022-11-21T17:19:18Z")

</div>

Hi @mnse and thank you for your answer.  
So if I convert my Processing code to p5.js I would have to convert the java libraries I wanted to import too? Is there no way to import java libraries into a p5.js program?  
Thank you

---

<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:** [November 21, 2022, 6:07pm UTC](https://discourse.processing.org/t/importing-java-libraries-into-embed-processing-sketch-online/39693/4 "2022-11-21T18:07:58Z")

</div>

> [@zellwd](#):
>
> This is the part of my code that needs to be replaced:

Do you really need a BufferedReader?

> **[BufferedReader / Reference](https://processing.org/reference/BufferedReader.html)**
>
> A BufferedReader object is used to read files line-by-line as individual String objects. Starting with Processing release 0134, all files loaded and saved by the Processing …

Isn’t **loadStrings()** & **saveStrings()** enough for your sketch?  
[https://GoToLoop.GitHub.io/processing-js.github.io/reference/loadStrings\_/](https://GoToLoop.GitHub.io/processing-js.github.io/reference/loadStrings_/)  
[https://GoToLoop.GitHub.io/processing-js.github.io/reference/saveStrings\_/](https://GoToLoop.GitHub.io/processing-js.github.io/reference/saveStrings_/)

B/c your Java Mode sketch would be able to run on the web if you stick w/ Processing’s API:  
[https://GoToLoop.GitHub.io/processing-js.github.io/reference/](https://GoToLoop.GitHub.io/processing-js.github.io/reference/)

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [November 21, 2022, 6:08pm UTC](https://discourse.processing.org/t/importing-java-libraries-into-embed-processing-sketch-online/39693/5 "2022-11-21T18:08:06Z")

</div>

Hi @zellwd,

All depends on your code…

P5js and processing java build up a similar framework ie. setup/draw.

Regarding the libraries. No! Java and Javascript are different things.

But if you want to implement backend logic with java you can use a server-site approach ie. RestAPI calls etc.  
But that mean you need an appserver running ie. tomcat.

As said, all depends on your code and what it does … and if you could tell what libraries you want to use for what we can see if there are similar libraries for js…

Cheers  
— mnse
