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 › Eclipse INTO Processing
Page Index Toggle Pages: 1
Eclipse INTO Processing (Read 2107 times)
Eclipse INTO Processing
Mar 26th, 2010, 2:44am
 
I have read and and successfully tested the "Processing IN Eclipse " tutorial.
What I need now is to use within Processing a code which has been written with Eclipse. Is it possible?
Re: Eclipse INTO Processing
Reply #1 - Mar 26th, 2010, 5:35am
 
Yes.
Re: Eclipse INTO Processing
Reply #2 - Mar 26th, 2010, 6:46am
 
you still have to do some minor changes though. its mostly pretty easy. you only have to remove some lines.
Re: Eclipse INTO Processing
Reply #3 - Mar 27th, 2010, 12:09am
 
Thank you!
Is there a document where the changes to be made to get a true Java code running on Processing are listed?
For instance if I try to run this example - coming from an Eclipse tutorial -:
Code:
package org.totalbeginner.tutorial;
import java.util.ArrayList;
import junit.framework.TestCase;
public class MyLibraryTest extends TestCase {
private Book b1;
private Book b2;
private Person p1;
private Person p2;
private MyLibrary ml;
// test constructor
public void testMyLibrary() {
MyLibrary ml = new MyLibrary("Test");
assertEquals("Test", ml.name);
assertTrue(ml.books instanceof ArrayList);
assertTrue(ml.people instanceof ArrayList);
}
public void setup() {
b1 = new Book("Book1");
b2 = new Book("Book2");
p1 = new Person();
p2 = new Person();
p1.setName("Fred");
p2.setName("Sue");
ml = new MyLibrary("Test");
}
public void testAddBook() {
//create test objects
setup();
//test initial size is 0
assertEquals(0, ml.getBooks().size());
ml.addBook(b1);
ml.addBook(b2);
assertEquals(2, ml.getBooks().size());
assertEquals(0, ml.getBooks().indexOf(b1));
assertEquals(1, ml.getBooks().indexOf(b2));
ml.removeBook(b1);
assertEquals(1, ml.getBooks().size());
assertEquals(0, ml.getBooks().indexOf(b2));
ml.removeBook(b2);
assertEquals(0, ml.getBooks().size());
}
}

with Processing I get plenty of errors.
Please give me a reference!
Re: Eclipse INTO Processing
Reply #4 - Mar 30th, 2010, 2:03pm
 
"plenty of errors" is a bit vague.

That's pure Java code, why do you want to run that in Processing instead of just using Eclipse?
Re: Eclipse INTO Processing
Reply #5 - Apr 2nd, 2010, 12:29pm
 
Your java code could work in the PDE if you attend to the following:

1. It's pure java code, so needs a .java extension.
2. The class is named testMyLibrary, so needs to be in a file named testMyLibrary.java
3. The first line declares a package structure (org.totalbeginner.tutorial), which isn't easily mirrored in a processing project. You could remove that line.
4. The class imports a JUnit library. In order to compile, it will need JUnit in your library folder.

However, like PhiLho suggests, it's much simpler to keep all your pure Java code maintained in Eclipse, then export it as a packaged-up JAR into a library folder, for use in all your processing sketches. Best of both worlds, then.
Re: Eclipse INTO Processing
Reply #6 - Apr 3rd, 2010, 9:49am
 
n.hurst wrote on Apr 2nd, 2010, 12:29pm:
[...]
However, like PhiLho suggests, it's much simpler to keep all your pure Java code maintained in Eclipse, then export it as a packaged-up JAR into a library folder, for use in all your processing sketches. Best of both worlds, then.


It depends what you want to do. I had several students working with processing and the idea was to share code and learn from each other. Since some wanted to use Eclipse and some the Processing IDE we agreed on exporting all Eclipse code in a form that can be read by Processing (stored in a subversion repository sitting in the sketch folder). We have used the following simple ant script to make this a bit easier.

Andreas

Code:


<!-- Replace the project and paths names with thos of your project -->
<project name="GWDistort">
<property name="srcdir" value="../src"/>
<property name="builddir" value="../GWDistort"/>
<property name="datadir" value="../src/data"/>

<tstamp>
  <format property="TODAY_UK" pattern="ddMMyyhhmm" locale="en,UK"/>
</tstamp>

<mkdir dir="${builddir}" />
<echo>Start Clean</echo>
<delete>
   <fileset dir="${builddir}" includes="**/*.pde"/>
   <fileset dir="${builddir}" includes="**/*.java"/>
 </delete>

<echo>Complete Clean</echo>

<echo>start copy</echo>
  <mkdir dir="${builddir}" />

<copy todir="${builddir}">
  <fileset dir="${srcdir}"/>
  </copy>

<copy todir="${builddir}/data">
  <fileset dir="${datadir}"/>
  </copy>

  <!-- Replace the names in the following line with your main Java file! -->
<move verbose="true" file="${builddir}/GWDistort.java" tofile="${builddir}/GWDistort.pde"/>

<echo>Complete copy</echo>

<replace dir="${builddir}">
 <include name="**/*.pde"/>
 <replacetoken>@</replacetoken>
 <replacevalue>//</replacevalue>
</replace>

<replace dir="${builddir}">
 <replacetoken>package</replacetoken>
 <replacevalue> //package</replacevalue>
 </replace>

</project>
Page Index Toggle Pages: 1