# How do I compile a Processing file to a JAR file?

**URL:** https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427
**Category:** Beginners
**Created:** [July 16, 2023, 11:13am UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427 "2023-07-16T11:13:23Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![nuhuhwy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nuhuhwy/32/18485_2.png) [@nuhuhwy](https://discourse.processing.org/u/nuhuhwy)
#### Post date: [July 16, 2023, 11:13am UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/1 "2023-07-16T11:13:23Z")

</div>

Lets just say i have this code:

```auto
void setup() {
size(960,540);
background(255);
fill(0);
text("this works",width/2,height/2);
}

```

How can i make this code into a standalone jar file, that can be executed to just work.  
(i want to use this to put on a server, which only supports jar files)  
I already tried compiling processing code to a jar file which didnt work.

I know how to create a java class file & run it but when i try to make processing into one file it doesnt work.

I wish processing would just directly compile in either one exe or just a jar… ;-;

---

<div class="post-metadata">

### Author: ![sterretje](https://avatars.discourse-cdn.com/v4/letter/s/cdc98d/32.png) [@sterretje](https://discourse.processing.org/u/sterretje)
#### Post date: [July 16, 2023, 12:49pm UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/2 "2023-07-16T12:49:21Z")

</div>

Note that I’m new to this game. Does it have to be a jar file?

> [@nuhuhwy](#):
>
> I already tried compiling processing code to a jar file which didnt work.

How?

I’ve just tested it in Processing 4.2 on a Windows system. I used _file → export application_ and selected both Windows and Linux which resulted in the following (it does not result in a jar file but an executable).

**Windows**  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/d/9/d9c1a4a37c321ba591982db90382ba16178f496e.png)

**Linux**  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/c/3/c3aa005bcef6ba2bccc1588129c419f4fc4a87e6.png)

Running the exe on Windows worked as expected. You can remove the source directory as far as I know.

---

<div class="post-metadata">

### Author: ![nuhuhwy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nuhuhwy/32/18485_2.png) [@nuhuhwy](https://discourse.processing.org/u/nuhuhwy)
#### Post date: [July 16, 2023, 6:14pm UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/3 "2023-07-16T18:14:09Z")

</div>

i need a jar file because the server im using only accepts .jar files !

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [July 16, 2023, 7:42pm UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/4 "2023-07-16T19:42:26Z")

</div>

When you export a file in Processing it puts the compiled app inside a folder in your sketch folder. Inside the app folder should be a .java file of your project. Have you tried converting the .java file to a .jar file? The conversion process uses the command line and is found with a Google search.

---

<div class="post-metadata">

### Author: ![nuhuhwy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nuhuhwy/32/18485_2.png) [@nuhuhwy](https://discourse.processing.org/u/nuhuhwy)
#### Post date: [July 17, 2023, 6:05pm UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/5 "2023-07-17T18:05:35Z")

</div>

it just gives me errors on anything processing related

---

<div class="post-metadata">

### Author: ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)
#### Post date: [July 17, 2023, 11:16pm UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/6 "2023-07-17T23:16:45Z")

</div>

Hi

here’s hints and tips may helps

> <https://stackoverflow.com/questions/20447824/exporting-processing-to-a-jar-file>

---

<div class="post-metadata">

### Author: ![nuhuhwy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nuhuhwy/32/18485_2.png) [@nuhuhwy](https://discourse.processing.org/u/nuhuhwy)
#### Post date: [July 18, 2023, 7:14pm UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/7 "2023-07-18T19:14:11Z")

</div>

problem is that both ways documented there dont work.

---

<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: [July 20, 2023, 9:56am UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/8 "2023-07-20T09:56:55Z")

</div>

Hi @nuhuhwy,

> [@nuhuhwy](#):
>
> i need a jar file because the server im using only accepts .jar files !

would you please elaborate a bit more what you’re trying to achieve ?  
If you export for linux your jar is already generated by the exporter beside the dependent libs.

ie:  
Dummy example code (ExportExample.pde)…

```auto
void setup() {
	size(500,500);
}

void draw() {
  background(0);
  translate(width/2,height/2);
  rotate(radians(frameCount));
  stroke(255);
  line(0,0,width/4,0);
}

```

…after Exporting it …

```auto
$ find ExportExample/linux-amd64/lib -print
ExportExample/linux-amd64/lib/core.jar
ExportExample/linux-amd64/lib/ExportExample.jar <-------- HERE ---------------
ExportExample/linux-amd64/lib/gluegen-rt.jar
ExportExample/linux-amd64/lib/jogl-all.jar
ExportExample/linux-amd64/lib/libgluegen_rt.so
ExportExample/linux-amd64/lib/libjogl_desktop.so
ExportExample/linux-amd64/lib/libjogl_mobile.so
ExportExample/linux-amd64/lib/libnativewindow_awt.so
ExportExample/linux-amd64/lib/libnativewindow_drm.so
ExportExample/linux-amd64/lib/libnativewindow_x11.so
ExportExample/linux-amd64/lib/libnewt_drm.so
ExportExample/linux-amd64/lib/libnewt_head.so

```

which contains your stuff:

```auto
$ jar -tf ExportExample/linux-amd64/lib/ExportExample.jar
META-INF/MANIFEST.MF
ExportExample.class <---------------- HERE ------

```

look into it shows the used function on higher level.

```auto
$ javap ExportExample.class
Compiled from "ExportExample.java"
public class ExportExample extends processing.core.PApplet {
  public ExportExample();
  public void setup(); <---------------- HERE ------
  public void draw(); <---------------- HERE ------
  public void settings();
  public static void main(java.lang.String[]);
}

```

in more detail the draw function (for relevant calls):

```auto
  public void draw();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=5, locals=1, args_size=1
         2: invokevirtual #16 // Method background:(I)V
        20: invokevirtual #27 // Method translate:(FF)V
        25: getfield #31 // Field frameCount:I
        29: invokestatic #34 // Method radians:(F)F
        32: invokevirtual #38 // Method rotate:(F)V
        39: invokevirtual #42 // Method stroke:(I)V
        53: invokevirtual #45 // Method line:(FFFF)V
        56: return

```

Cheers  
— mnse

---

<div class="post-metadata">

### Author: ![nuhuhwy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nuhuhwy/32/18485_2.png) [@nuhuhwy](https://discourse.processing.org/u/nuhuhwy)
#### Post date: [July 20, 2023, 11:17am UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/9 "2023-07-20T11:17:17Z")

</div>

What I am trying to achieve is having a processing sketch in a one file jar.

I followed both tutorials which someone sent me In this thread, but none of the worked.

When I try to open the jars, that come when exporting the code to Linux, I go to the lib folder and try running all jars at the same time - doesn’t work. Command line - doesn’t work, gives me errors on class could not be found.

In the file called what you named the sketch is bash code and it opens jogl-all.jar, gluegen.jar, core.jar & _nameofthesketch_.jar

When running this bash script it will open the sketch fine.

My question is, how do I convert everything in the “linuxamd64” folder to just one beautiful jar file that when klicked opens the windows, just like running the bash file in the command prompt.

It needs to be one jar file. That’s my question, I hope I explained it good enought 🙂

---

<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: [July 21, 2023, 7:29am UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/10 "2023-07-21T07:29:02Z")

</div>

Hi @nuhuhwy,

Ahh! Ok! Understood…  
In principle that isn’t really a hard challenge, if you know how java jar’s work. 🙂

_Starting on the stage after export application already done_  
I made an example video to show …  
 ![ezgif.com-optimize (1)](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/4/3/43bcf4d8b9338016608a4786f7085766303f033e.gif)

Just keep in mind that you need a proper working X11 Environment.  
For stuff like fancy opengl etc you need to set the \*.so available to your java-lib directory.  
But for simple cases the steps in the video should be sufficient …

Cheers  
— mnse

---

<div class="post-metadata">

### Author: ![nuhuhwy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nuhuhwy/32/18485_2.png) [@nuhuhwy](https://discourse.processing.org/u/nuhuhwy)
#### Post date: [July 21, 2023, 4:40pm UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/11 "2023-07-21T16:40:45Z")

</div>

Can i just copy the stuff in the build\_fat\_jar.sh file?

---

<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: [July 21, 2023, 6:09pm UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/12 "2023-07-21T18:09:41Z")

</div>

Hi @nuhuhwy ,

Sure! You can use every information I gave…

Cheers  
— mnse

---

<div class="post-metadata">

### Author: ![nuhuhwy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nuhuhwy/32/18485_2.png) [@nuhuhwy](https://discourse.processing.org/u/nuhuhwy)
#### Post date: [July 21, 2023, 6:45pm UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/13 "2023-07-21T18:45:52Z")

</div>

@mnse could you theoretically send it to me because i cant see exactly what is in the video!  
Thank you!

---

<div class="post-metadata">

### Author: ![nuhuhwy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nuhuhwy/32/18485_2.png) [@nuhuhwy](https://discourse.processing.org/u/nuhuhwy)
#### Post date: [July 21, 2023, 7:48pm UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/14 "2023-07-21T19:48:40Z")

</div>

```auto
#!/bin/bash

MAIN=${PWD##*/}}
echo "${PWD##*/}"

rm -rf tmp finished_build.jar 2>/dev/null

mkdir tmp

for file in $(ls -1 linux-amd64/lib/*.jar)
do
    echo "Currently extracting file... ( $file)"
    (cd tmp;jar xf ../$file)
done

jar -cfe finished_build.jar $MAIN -C tmp .

rm -rf tmp

java -jar finished_build.jar &

```

this is the code, i copied of your. If there is any error please tell me! Thank you for all your time thats wasted mabye because i forgot something 😃

---

<div class="post-metadata">

### Author: ![nuhuhwy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nuhuhwy/32/18485_2.png) [@nuhuhwy](https://discourse.processing.org/u/nuhuhwy)
#### Post date: [July 21, 2023, 8:20pm UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/15 "2023-07-21T20:20:26Z")

</div>

I fixed it:!!  
This is the corrected code!  
This doesnt work on windows for some reason, you need to install java first!

```auto
#!/bin/bash

MAIN="${PWD##*/}"

rm -rf tmp finished_build.jar 2>/dev/null

mkdir tmp

for file in $(ls -1 linux-amd64/lib/*.jar)
do
    echo "Currently extracting file... ( $file)"
    (cd tmp;jar xf ../$file)
done

jar -cfe finished_build.jar "$MAIN" -C tmp .

rm -rf tmp

java -jar finished_build.jar &

```

---

<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: [July 22, 2023, 5:57am UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/16 "2023-07-22T05:57:43Z")

</div>

Hi @nuhuhwy,

Your answer (which you’ve marked as solution 🤔) is not correct !?

> [@nuhuhwy](#):
>
> This doesnt work on windows for some reason

The bash script can be used on Linux but also on windows if you’ve bash installed by ie. WSL, cygwin, git-bash, etc.

> [@nuhuhwy](#):
>
> you need to install java first!

That’s also not true as you’ve the required commands (java, jar) already rolled out by processing itself. But for sure you need to point to it, by either use an absolute path or set it in your PATH environment variable…

Also the question marks only needed if your sketch would have any fancy names with blanks or hyphens, etc.

Cheers  
— mnse

PS: please consider to mark the post which pointing you to a possible solution as solution and not your “fix”.

---

<div class="post-metadata">

### Author: ![nuhuhwy](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nuhuhwy/32/18485_2.png) [@nuhuhwy](https://discourse.processing.org/u/nuhuhwy)
#### Post date: [August 6, 2023, 11:43pm UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/17 "2023-08-06T23:43:30Z")

</div>

So i tried compiling with the P2D renderer, and it doesnt work. Do you have a solution?

---

<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: [August 7, 2023, 10:19am UTC](https://discourse.processing.org/t/how-do-i-compile-a-processing-file-to-a-jar-file/42427/18 "2023-08-07T10:19:20Z")

</div>

Hi @nuhuhwy,

As you not showing me any error message I can only guess you not having the necessary .so libraries accessible via LD\_LIBRARY\_PATH.

Cheers  
— mnse
