# Create jar file from sketch in java

**URL:** <https://discourse.processing.org/t/create-jar-file-from-sketch-in-java/29267>\
**Category:** Coding Questions\
**Created:** [April 10, 2021, 7:08pm UTC](https://discourse.processing.org/t/create-jar-file-from-sketch-in-java/29267 "2021-04-10T19:08:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cocconat](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@cocconat](https://discourse.processing.org/u/cocconat)\
**Post date:** [April 10, 2021, 7:08pm UTC](https://discourse.processing.org/t/create-jar-file-from-sketch-in-java/29267/1 "2021-04-10T19:08:23Z")

</div>

Hi,

I am trying to pack this into a JAR file with IntelliJ IDEA (I can also change IDE if needed, but I d rather stick to this).  
The project runs in the IDE if I run the file. Honestly, I don’t really know which is the entry point!

```auto
package main.com.test;
import processing.core.PApplet;

public class MyMain extends PApplet {

    public void settings() {
        size(500, 500);
    }

    public void draw(){
        background(64);
        ellipse(mouseX, mouseY, 20, 20);
    }

    public static void main (String... args) {
        MyMain pt = new MyMain();
        runSketch(new String[]{"myMain"}, pt);
    }

```

Following this guide [1] I created a Manifest file and added the processing library -that is exported into the correct folder under core.jar -

```auto
Manifest-Version: 1.0
Main-Class: main.com.test.MyMain

```

and the built the artifact (Build-\> Artifacts) in IntelliJ

then from terminal run and obtain

$ java -jar out/artifacts/TestJar/archive.jar  
Error: Could not find or load main class main.com.test.MyMain

I am sure it’s a stupid problem but I spent the last 5 hours of my life trying this and I am very frustrated.

Thanks,  
Alessio  
[1] [Creating an Executable JAR in Intellij IDEA | Karthic Raghupahti](https://blog.karthicr.com/posts/2016/07/10/creating-an-executable-jar-in-intellij-idea/)

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [April 11, 2021, 8:26am UTC](https://discourse.processing.org/t/create-jar-file-from-sketch-in-java/29267/2 "2021-04-11T08:26:21Z")

</div>

A more stable way to work is to use maven, then your not reliant on ide. Further I would expect your sketch to look like this:-

```java
package main.com.test;
import processing.core.PApplet;

public class MyMain extends PApplet {
     public void settings() {
        size(500, 500);
    }

    public void draw(){
        background(64);
        ellipse(mouseX, mouseY, 20, 20);
    }

  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "main.com.test.MyMain" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}

```

Note the package name prefix in appletArgs. Now processing does not officially release maven artifacts, which is unfortunate, but there’s nothing stopping you creating your own (core.jar would be a start). The latest version available from maven central is 3.3.7 which might be good enough.  
See snippet below showing part of pom.xml to create a main manifest using maven.

```xml
  <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>main.com.test.MyMain</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>

```

---

<div class="post-metadata">

**Author:** ![cocconat](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@cocconat](https://discourse.processing.org/u/cocconat)\
**Post date:** [April 11, 2021, 1:51pm UTC](https://discourse.processing.org/t/create-jar-file-from-sketch-in-java/29267/3 "2021-04-11T13:51:51Z")

</div>

Hi,

thanks a lot for your answer and time. From your suggestion to use a general framework I understood something important:  
_I should not use the Java interface to the Processing library if I have no idea about how Java works and I am not interested in it!_

Indeed, I have no idea what else to write in the pom.xml file and the difference between a maven artifact and the core.jar file in the library folder.

Hence, I opened the code from the processing ide. -Which is not as pleasant and helpful as the IntelliJ ide-. Changet slightly the code. And run the ¨Export Application¨ in **File**.

Et voila´ I have the application in exe and bush files. Thank you, Processing developers, to make it easy.

The code is accessible from this shared folder till 1 May 2021

> **[ownCloud - Your Cloud, Your Data, Your Way!](https://owncloud.gwdg.de/index.php/s/qbM62BFdCXtLjNB)**
>
> GiocoPopolazioni is publicly shared

---

<div class="post-metadata">

**Author:** ![HackinHarry](https://avatars.discourse-cdn.com/v4/letter/h/3e96dc/32.png) [@HackinHarry](https://discourse.processing.org/u/HackinHarry)\
**Post date:** [April 11, 2021, 3:51pm UTC](https://discourse.processing.org/t/create-jar-file-from-sketch-in-java/29267/5 "2021-04-11T15:51:30Z")

</div>

Aww Man, that is awesome. I tried this oscilloscope a few months ago to understand the PPM signal of my RC receiver. It was a big help, thanks. It is a surprise to see it on this forum, but it is written in processing afterall.

EDIT: Wow, I unzipped the wrong application.linux64.zip and it was that oscilloscope. I unzipped your application and it’s still awesome. I like the graph. Nice. I assume e has something to do with population growth and stability.
