edit upload recent print
Search

                                          



* WikiDocs

Main » Eclipse

Using Processing with Eclipse


   EclipseP5Exporter || Processing Applications || RiTa/OpenGL and Eclipse || Useful ShortCuts


Note: Getting a heap memory error? To increase the memory size for an application in Eclipse, go to Menu: Run -> Run-configurations -> Arguments -> VM-Arguments and add the following (for 384 mb of heap space): -Xmx384m


NOTE: Many the steps below are now fully automated by the new Proclipsing plugin -- see Proclipsing instructions here

If you have already installed and tested eclipse, skip to step 10.
  1. Go to the eclipse [http://www.eclipse.org/downloads/ | downloads page]] and download the latest version of Eclipse (choose 'Eclipse IDE for Java Developers') to the desktop.
  2. If necessary, extract the archive file to the desktop (double-clicking will generally do this)
  3. Drag the eclipse folder into /Applications (mac), or into a convenient place on windows, e.g., C:\Eclipse
  4. OPTIONAL: drag Eclipse into the dock (mac), or into the quick-launch bar (win) to create a convenient shortcut
  5. Double-click Eclipse.app or Eclipse.exe (the program) to run Eclipse
  6. Eclipse will ask for a workspace location (accept the default location or choose one of your own that is memorable).
  7. If the welcome screen pops up, close it.
  8. Create a test Java Application (if you've already run a Java app from eclipse, you can skip to step 10.)
    1. Create new project: (Menu) File > New > Java Project
    2. Set the project name, e.g., FirstJavaProject
    3. Leave all defaults, click 'Finish'
    4. Create a new class in the project: File -> New -> Class
    5. Set the class name, e.g., HelloWorld
    6. Leave all defaults, click 'Finish'
    7. Add the following text to the file (inside the class):

          public static void main(String args[]) {
              System.out.println("Hello World!");
          }
  9. Run your application: Run -> Run-As -> Java Application. You should see your output text appear in the console window.

10. Now create a simple Processing application

  1. Create a new package in your project: File > New > Package (Using packages is generally a good idea and Processing will complain if you don't)
  2. Package name: mypackage
  3. Create new class inside the package: File > New > Class
  4. Class Name: HelloProcessing
  5. Leave all defaults, click 'Finish'.
  6. Next we need to copy the Processing classes (core.jar) into our project.
    1. The location of this file will vary depending on where you installed Processing, but on Windows it might be C:\Program Files\Processing1.x\lib\core.jar. On a Mac, Processing will usually be in /Applications/Processing1.x, but to view the contents of this directory you must first right-click and choose 'Show Package Contents', then navigate down (via the to Contents/Resources/Java/core.jar).
    2. Copy/Paste or Drag & Drop the core.jar file into your Eclipse project (at the top level is fine). If you Copy/Paste, you may need to refresh your project before it shows up (Eclipse->File->Refresh).
    3. Next, right-click on the core.jar within Eclipse and select 'Build-Path'->'Add-to-Build-Path'.
    4. Note: You can also 'link' to jar files without copying them, but this can cause minor problems, especially on the Mac, so for new users I recommend the steps above.
  7. Now tell Java that you want it to 'import' the processing classes when it compiles your code by adding this line at the very top of your Java file (HelloProcessing.java):

        import processing.core.*;
  8. Below the import section, have your class (HelloProcessing) extend from PApplet as follows:

        public class HelloProcessing extends PApplet {


        }
  9. Inside the class, add the setup and draw functions that Processing expects (Important: be sure to add the 'public' modifier -- see screenshot below)

        public void setup() {
            size(400, 400);
        }

        public void draw() {
            background(255);
            stroke(0);
            ellipse(200,200,200,200);
        }

        Note: do NOT use variables as arguments to size() as this will break the export function
  10. Now run your applet: Run > Run-As > Java Applet. If all went according to plan, you should see your sketch pop up in the 'applet viewer' window, and any errors or messages should go to the eclipse console. Remember to test any sketches in a browser before posting them to the web; just b/c something runs in eclipse, doesn't (necessarily) mean it will run in either Processing or a web-browser.
  11. Lastly, add an external file (a font or image or sound file) to your sketch and make sure you can load it in Eclipse. To do this, create a 'data' folder inside the 'src' directory (File -> New -> Folder) in your Eclipse project, then drag or copy your external file into that. Add the usual code to your sketch to load it and give it a try. Note: again you may need to 'refresh' after adding new files: 'Eclipse->File->Refresh'.

   NOTE: See this link if you want to run your program as an application in Eclipse.

   NOTE: See this link if you want to enable Processing-style exports from within Eclipse.

   NOTE: As of this writing, Processing supports up to Java 1.5. Therefore if you want to be Processing-compatible, make sure the 'Compiler-compliance-level' (in Eclipse->Preferences->Java->Compiler) is set to 1.5, not 1.6 (though you can still use the 1.6 JRE if you like.)


      A 1st Processing program in Eclipse


Instructor: Daniel C. Howe

Resources

     MORE

Page last modified on November 02, 2010, at 11:17 AM EST