简体   繁体   中英

How to use Processing 3 on IntelliJ IDEA?

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

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 .

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.

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.

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

  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 press CTRL + 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-XYZ/core/library
    • for other dependencies, look into modes library
    • eg: for SVG export , add processing-XYZ/modes/java/libraries/svg/library

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM