19

I'd like to use the IntelliJ IDEA IDE to develop some app using Processing 3. How can I do that ?

There are only tutorials on how to use Processing 2, but I think things have changed enough so that those tutorials do not work anymore.

Thank you

ypicard
  • 3,593
  • 3
  • 20
  • 34

6 Answers6

39

It's hard to answer general "how do I do this" type questions. Stack Overflow is designed more for "I tried X, expected Y, but got Z instead" type questions. You'll have much better luck if you try something out and post an MCVE along with a specific question if you get stuck. You say you think things have changed enough so that those tutorials don't work anymore- could you test that assumption by trying it out?

Because those tutorials will still work. A few things have changed, such as the removal of the ability to embed a PApplet directly into a Swing application. But 90% of the rest of the tutorials should work fine.

Step 1: Add the Processing library to your classpath. This includes the core and any JOGL dependencies you need.

Step 2: Create a class that extends PApplet and add your code there.

Step 3: Call PApplet.main("YourSketchNameHere"); to launch your sketch.

Here is a little example that shows those steps:

import processing.core.PApplet;

public class ProcessingTest extends PApplet{

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

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

    public static void main(String... args){
        PApplet.main("ProcessingTest");
    }
}

Please try something out and post a specific question if you get stuck. Good luck.

Shameless self-promotion: I wrote a tutorial on using Processing as a Java library, available here.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
  • Hi, thank you for your answer. I am still new to the import process of external libraries, nut I understand the main lines. When you say to import the Processing library, is it supposed to be a jar, or should I import the files from here : https://github.com/processing/processing ? Because i can't find a core.jar anywhere... – ypicard Apr 25 '16 at 05:22
  • @ypicard The core jar comes with Processing itself. But you could use the source as well. It really depends on exactly what you want to do. But if you're not familiar with how a classpath works or how to find jars, why are you trying to use a more advanced IDE? You might be better off just sticking with the Processing editor for now. – Kevin Workman Apr 25 '16 at 13:27
  • 1
    Because we all have to learn one day or another ;) And the base Processing IDE isn't really that powerful... I managed to get the jars from the application itself as you said, imported them in my project, and now when I try to run your code, it get a ClassNotFoundException. Apparently, the **ProcessingTest** Class can't be found in my imports. I dug in the source files on Github and managed to find a **ProcessingTestUtil** Class, but it is not the one I am looking for... Where should I go now ? – ypicard Apr 26 '16 at 13:30
  • @ypicard What kind of power do you need that the Processing IDE doesn't offer? Honestly, unless you have a very good reason to use an IDE, I don't know why you'd even want to switch over. But please keep in mind that my code is just an example. I happened to name my class `ProcessingTest`, but you might have named yours something different. Also please keep in mind how packages work- you can't import a class that's not in a package. – Kevin Workman Apr 26 '16 at 13:35
  • Aha this was a stupid mistake of mine. Thanks for are the help, it worked ! – ypicard Apr 26 '16 at 13:39
  • Instead of `PApplet.main("ProcessingTest");` you could do `PApplet.main(ProcessingTest.getClass().getCanonicalName())` - the argument should be the package+class name of your sketch. – PapaFreud Mar 03 '17 at 12:02
  • Also: Using maven, all you need to do is add processing.org:core https://mvnrepository.com/artifact/org.processing/core to your pom.xml. – PapaFreud Mar 03 '17 at 12:04
  • BTW, are there any scripts/convertors to convert Java code to full-blown PDE code to be run in Processing ide? – WebComer Jan 31 '18 at 20:40
  • @WebComer Not that I know of, and honestly that's probably going the wrong direction. The Processing IDE takes "pde code" and converts it into Java. Going the other way doesn't make a ton of sense. But the Processing editor will work with most Java code, you just have to change a few things (get rid of your main class and main method). If you have a follow-up question please post it in a new question post. – Kevin Workman Jan 31 '18 at 21:55
3

I up voted Kevin's answer but also went ahead and created a gradle project that you can use with or without an IDE or processing. Git Commit to processing project

Edit doesn't work for video libraries. i tried to get the libraries needed but that is not my best area and have resorted to use P3 for those projects.

mavriksc
  • 1,130
  • 1
  • 7
  • 10
1

The easiest way for me is to create a new maven project and add proessing through maven.

After that you create your class that extends PApplet (I named it Main).

In Run > Edit Configuratins add the main class name and the same name for program arguments.

brianelete
  • 23
  • 1
  • 6
0

Create a maven project in Intellij. In one folder (example "libs") you put all libs which are probably not yet available via mavencentral, but with the help of maven you can handle the installation automatically.

libs

Then inside the pom.xml you add a maven-install-plugin, which will install your libs for you inside your local repository.

        <profiles>
        <profile>
        <id>Assembly Gui</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>${maven-install-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>install-controlP5-lib</id>
                            <goals>
                                <goal>install-file</goal>
                            </goals>
                            <phase>validate</phase>
                            <configuration>
                                <groupId>sojamo.de</groupId>
                                <artifactId>controlP5</artifactId>
                                <version>${controlP5.version}</version>
                                <packaging>jar</packaging>
                                <file>${basedir}/libs/controlP5-2.3.0.jar</file>
                                <generatePom>true</generatePom>
                            </configuration>
                        </execution>
                        <execution>
                            <id>install-appleJar-lib</id>
                            <goals>
                                <goal>install-file</goal>
                            </goals>
                            <phase>validate</phase>
                            <configuration>
                                <groupId>processing.org</groupId>
                                <artifactId>appleJar</artifactId>
                                <version>${appleJar.version}</version>
                                <packaging>jar</packaging>
                                <file>${basedir}/libs/apple.jar</file>
                                <generatePom>true</generatePom>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

Note that both libs are "installed" during the "validate" phase, so the order is

  1. clean
  2. validate (here your processing libs are installed)
  3. compile (and here they can be retrieved later from your local repo)
  4. test
  5. ...

Because the maven-install-plugin was inserted as a profile (active as default), you can switch it off inside Intellij for saving a bit of time during builds once it runned at least once.

Profiles in Intellij

0
  1. Download the .jar files from their official site
  2. Create any Java (or Kotlin) project in IntelliJ
    • for this tutorial I've used Maven
  3. Inside IntelliJ, go to File > Project Structure
    • or pressCTRL + ALT + SHIFT + S at the same time
  4. Inside Project Settings > Libraries: Click Plus icon
    • navigate to the downloaded folders
  5. Add everything inside processing-X.Y.Z/core/library
    • for other dependencies, look into modes library
    • e.g.: for SVG export, add processing-X.Y.Z/modes/java/libraries/svg/library
andras
  • 3,305
  • 5
  • 30
  • 45
0

To make it easier to use Processing within an external IDE, I implemented a rudimentary wrapper. This will avoid the necessity to inject the Processing-Object to each created class that want to use Processing methods.

Have a look: Using Processing within external IDE

Syrious
  • 91
  • 2
  • 8