We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Processing (Beta) with Eclipse
Pages: 1 2 
Processing (Beta) with Eclipse (Read 54941 times)
Processing (Beta) with Eclipse
May 26th, 2005, 8:59pm
 
This post updates Toxi's post about integrating Processing (Alpha) with Eclipse. The text is by Toxi and edited by REAS. Let us know in this post if there are errors in these instructions.

Eclipse is an open source environment with all sorts of luxurious features like code hints and completion, error checking as you type, intelligent refactoring (renaming), javadoc generation etc. It's all quite heavyweight, but in short, it just ROCKS and above all, once setup correctly it works like a charm with the Processing libraries (as expected : ) !

If you feel you have slightly outgrown the PDE and are interested to check out eclipse, below are the steps to set you all up & running...

Before starting, make sure you have Eclipse working correctly. It's not easy, so make sure you have some of their tutorials working before tying to bring Processing in. http://www.eclipse.org/

1) If you haven't done so yet, download and install a recent version of the JavaSDK (v1.4.x or newer) from Sun's website

2) Go to the Eclipse download page and select latest stable build (3.0.2 as at time of writing). On the next page select "Eclipse SDK" (including the Java Development Tools). You'll need them as Eclipse itself is a very flexible IDE and is using plugins to handle various development types. The JDT plugins are needed for using eclipse with java.

3) Once installed (for Windows I recommend directly into C:\eclipse) - launch eclipse and select "new project" from the "file" menu. Select "java" and then "next". Now give a name to the project, eg. "HelloP5" and click on "next" again. In the new dialog, click on the "libraries" tab. You should see a list of installed JREs. However we need to manually add the Processing libraries. So select "add external JARs" and open the "lib" folder of your processing application (eg. C:\processing-0090\lib). Select "core.jar". Press "finish" to setup the project folders and confirm that this project will use the "java perspective".

4) By now you should see the interface has changed to the java perspective, with the "package explorer" on the left. For some good housekeeping, lets create a subfolder for storing all source files independently from the exported classes. Select "file menu > new > source folder" and use "src" as the folder name. Click "ok" to confirm. A new icon for that folder should now appear in the package explorer. please select it.

5) In order to write some code we first need to create a new class, so select "file menu > new > class" and name give it a name, eg. "HelloP5". (Note: for the later parts of this tutorial to work, you should name this class like your project name). Ignore the other options in that dialog for now and just press "ok". You'll see Eclipse opened the new source file for you and has filled in some basic default class definition code already.

6) If you ever had a look at the exported java file the Processing PDE is generating, you'll have seen that all your sketches are implemented as sub-class of the almighty PApplet. Eclipse can't know about that fact, so we'll have to tell it the compiler ourselves by adding "extends PApplet" to the class definition. here's some example code:

Code:

import processing.core.*;

public class HelloP5 extends PApplet{

public void setup(){
size(200, 200);
stroke(155,0,0);
}

public void draw(){
line(mouseX,mouseY,width/2,height/2);
}

}


7) Save the changes to the file and select "Run..." from the "Run" menu. Choose "java applet" and press "new" to create a new setting. The wizard will fill in all the necessary fields apart from the window dimensions, which default to 200 x 200 pixels. If your sketch is using anything different, you'll need to edit the settings under the "parameters" tab. Click "apply" and then "run". BTW, this step is only needed once per sketch, you can also run the currently selected sketch by pressing CTRL+F11.

8 ) If everything's setup correctly, you should now see your sketch in the java applet viewer.
Re: Processing (Beta) with Eclipse
Reply #1 - Jun 16th, 2005, 7:24pm
 
so has anyone gotten an ant build to work in eclipse with beta?  i'm following toxi's old instructions to the extent they apply to beta.  i've gotten everything to build, but i've done some strange things to get to that point, and as a result, my built applet won't run.  below is a log of what i've done to get where i am, perhaps someone can tell me where i went wrong....

toxi's original guide:
http://processing.org/discourse/yabb/YaBB.cgi?board=Integrate;action=display;num=1106256315

- in ant>runtime>classpaths, i included pde.jar, but comm.jar no longer exists.  not sure what to do here.

- as the class files that used to be hanging out in processing\lib\export are now all packed into core.jar, for classpath.processing.export i made a new folder and dumped the contents of core.jar into it, maintaining the processing>core>class files path.

this is enough to get a successful build, but the resulting jar seems to be missing something; it won't run in a browser or via command line.

(although i may not be doing the command line correctly?  java sketchName.jar sketchName yields a java.lang.NoClassDefFoundError for the ant-built jar, but it yields the same for processing-built jars.  hmmm...)

when i compare the contents of my ant-built jar with a similar processing-built jar, it appears to be the same, except that my class files are inside a package i made (called 'main').  so it seems like it *should* work...but no dice.

sooo...any thoughts would be MUCH appreciated....thanks!
Re: Processing (Beta) with Eclipse
Reply #2 - Jun 17th, 2005, 5:08pm
 
depth wrote on Jun 16th, 2005, 7:24pm:
- in ant>runtime>classpaths, i included pde.jar, but comm.jar no longer exists.  not sure what to do here.


that JAR was needed for serial port functionality, which in previous versions of Processing was core part of the engine. in Processing beta this has now been implemented as library and is not needed anymore (unless you're working with the Serial library).

Quote:
- as the class files that used to be hanging out in processing\lib\export are now all packed into core.jar, for classpath.processing.export i made a new folder and dumped the contents of core.jar into it, maintaining the processing>core>class files path.


just like the alpha versions of the Processing PDE, my original Ant build script was intended to export applets in a JDK1.1 compatible format. the class files you refer to were the 1.1 compiled P5 core classes, but can now be safely discarded as Processing Beta does currently not support 1.1 compatible byte code.

Quote:
this is enough to get a successful build, but the resulting jar seems to be missing something; it won't run in a browser or via command line.

(although i may not be doing the command line correctly  java sketchName.jar sketchName yields a java.lang.NoClassDefFoundError for the ant-built jar, but it yields the same for processing-built jars.  hmmm...)


i need to make some time v.soon to update my eclipse tutorial. at the moment i really couldn't say though, what might be causing this error as i haven't properly played around with beta yet... Sad
Re: Processing (Beta) with Eclipse
Reply #3 - Jun 20th, 2005, 5:33pm
 
I've not set up Eclipse yet, but does this code work?:

Code:
import processing.core.*; 

/**
* <p>An implementation of MyGUI class.</p>
*/

public class Cheese extends PApplet {
 
 color green;
 
 public void setup() {
   // Set applet size and framerate
   size(300, 300);
   background(153);
   framerate(25);
   // Setup colours
   green = color(0, 220, 30);
 }
 
 public void draw() {
   fill(green);
   noStroke();
   rect(40, 40, 50, 20);
 }
}


I'm trying to get Processing work with the BlueJ IDE (http://www.bluej.org/) but I keep getting the compiler error "cannot resolve symbol - class color not found" - I wondered if this was the same in Eclipse?
Re: Processing (Beta) with Eclipse
Reply #4 - Jun 20th, 2005, 6:15pm
 
We're good at answering our own questions. I installed Eclipse and followed through the above guide. As with BlueJ, when I tried to use the color variable I got the message "color cannot be resolved to a type" - so thats something common between Eclipse and BlueJ - they both fail to detect the color type.

Any ideas how to fix?
Re: Processing (Beta) with Eclipse
Reply #5 - Jun 20th, 2005, 6:30pm
 
the color type is actually just an int.
see fjen's reply (#48)

http://processing.org/discourse/yabb/YaBB.cgi?board=Integrate;action=display;num=1106256315;start=48
Re: Processing (Beta) with Eclipse
Reply #6 - Jun 21st, 2005, 12:01am
 
Thanks depth, got that issue sorted now. It never occured to me how much the preprocessor did to change the way normal Java compilers work to make life easier for the programmer.
Re: Processing (Beta) with Eclipse
Reply #7 - Jun 21st, 2005, 4:18pm
 
more details on the preprocessor can be found here:
http://cvs.sourceforge.net/viewcvs.py/processing/processing/app/preproc/README.txt?rev=1.1&view=auto

scroll past the technical details at the top and the middle of that document contains the info about what the preproc handles.
Re: Processing (Beta) with Eclipse
Reply #8 - Nov 25th, 2005, 7:19am
 
I have modified toxi tutorial for building applets package with ant from eclipse. You can download my project here:
http://gigaton.thoughtworks.com/~wmli/applet/HelloP5.zip

I have unjar the core.jar and jar it up with the classes built for the applet (HelloP5.class, Partical.class). I also modified the build.xml and add the build.properties so that the build process is no longer tie to Eclipse. If you have ANT setup in a windows system, you should be able to run "ant dist" in a dos prompt to build the applet.

These are the things that I have modified:
1).Instead of setup properties in the ant properties tab, I have add a build properties to stores the properties. These are the entries in the build.properties:
 project_name=HelloP5
 applet.width=200
 applet.height=200

2).I have separated the html file from the build.xml into a template under the html directory. I have used the <replace> target to replace the variables (e.g. %%project_name%% ) with the proper property values:
<copy file="${html}/index.html" tofile="${dist}/index.html" />
 <replace file="${dist}/index.html">
   <replacefilter token="%%project_name%%" value="${project_name}" />
   <replacefilter token="%%applet.width%%" value="${applet.width}" />
   <replacefilter token="%%applet.height%%" value="${applet.height}" />
   <replacefilter token="%%src.zipfile%%" value="${src.zipfile}" />
 </replace>

3).I have put the core.jar and pde.jar under the lib directory. The build.xml has been modified to reference the lib directory accordingly:
Added:
 <path id="master-classpath">
   <fileset dir="${lib}" />
 </path>
 ...
 <target name="compile" depends="init" description="compile the source">
   <!-- Compile the java code from ${src} into ${build} -->
   <javac fork="true" srcdir="${src}" destdir="${build}">
     <classpath refid="master-classpath" />
   </javac>
</target>

4).Unjar the core.jar to the build and put the result into final project jar file.
 Added:
   <!-- unjar core.jar to the build directory -->
   <unjar dest="${build}" src="${lib}/core.jar" />

 
 This is the link to the build result:
http://gigaton.thoughtworks.com/~wmli/applet/index.html

 Let me know if you have any questions.
Re: FAT Jar plugin
Reply #9 - Jan 31st, 2006, 3:26am
 
For those eclipse IDE users who need to package their code+libraries into a single executable JAR file, try Fat Jar.  It automatically extracts required library jar files then repackage it into your application jar file.  (since Java doesn't support nesting of Jars within Jars)

It's available at http://fjep.sourceforge.net/

It even has "ANT build xmlfile export" function so you can repeat the ANT building process via command line.

It also has the One-Jar option if the 3rd party library's license does not allow you to repackage the JARs.  It's more complicated but details can be found here: http://www-128.ibm.com/developerworks/library/j-onejar/index.html?ca=drs-j4904
Re: Processing (Beta) with Eclipse
Reply #10 - Mar 22nd, 2006, 2:39am
 
Hello,
I'm having trouble getting my built applet working properly.  I'm using Eclipse and a copy of wmli's ant build file.  When I try running my applet in the browser, it is unable to find the font file (which has been included in the jar).  I can get it to work if I copy the font file into the same directory as the jar, and then run it from the command line.  No such luck through the browser though.  Any help would be greatly appreciated.

Andrew
Re: Processing (Beta) with Eclipse
Reply #11 - Apr 20th, 2006, 3:49am
 
I had the same problem. I solved it by creating a bin/data folder in my project directory. Apparently the font file must be in a folder named data. The path to my font file was something like:

projectdirectory/bin/data/fontfile.vlw

Then I changed the following line of code in build.xml from

<copy todir="${build}">

to

<copy todir="${build}/data">

Also if you don't want a bin directory you could just have the data folder in your project directory and change the line:

<property name="data" location="bin/data" />

to

<property name="data" location="data" />

I know it's a little late but I hope that helps.
Re: Processing (Beta) with Eclipse
Reply #12 - Apr 21st, 2006, 7:00pm
 
Thanks for the suggestion.  I tried it and it didn't work for me Sad  Are you using the default package?  I didn't have problems until I started specifying a package.  Perhaps I'm missing something else though... Here is my setup in Eclipse:

Project
 |_src (source folder)
        |_packagename
        |       |_java files
        |_data
               |_font file

This is also mirrored in my bin folder.

In my actual code, I load the font like so:
font = loadFont("data/FranklinGothic-Medium-12.vlw");

In my build file I'm using this to copy the data:
<property name="data" location="bin/data"/>
<copy todir="${build}/data">
 <fileset dir="${data}">
   <include name="**/*" />
 </fileset>
</copy>

It seems to work properly, as when I unjar the file, it extracts the font to a data folder.

I'm pretty sure the problem is using a non-default package, but I have no clue how to fix this Sad
Re: Processing (Beta) with Eclipse
Reply #13 - May 3rd, 2006, 11:06pm
 
Try putting your data folder in the project folder instead of the src folder and load your font using loadFont("FranklinGothic-Medium-12.vlw");

if you set your directories up this way you need to change
this:
 <property name="data" location="bin/data"/>
to this:
<property name="data" location="data" /> in your build.xml file.

I am using non-default packages and this setup works for me.
Re: Processing (Beta) with Eclipse
Reply #14 - May 4th, 2006, 8:18pm
 
Thank you so much!  This is finally working for me Smiley
Pages: 1 2