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 › Netbeans and Processing
Pages: 1 2 
Netbeans and Processing (Read 23295 times)
Netbeans and Processing
Oct 4th, 2007, 5:35am
 
As I couldn't find any info on using Processing with NetBeans, I thought I would quickly post how to do it.

- Open NetBeans and File > New Project
- Select 'Java Application' and hit Next
- Give the project a name eg: LetsP5 and leave the other settings as is (Set as Main Project and Create Main Class are checked) then hit Finish
- Right click on the 'Libraries' folder in the left hand column and "Add JAR/Folder", then in the dialog box locate the "core.jar" file inside Applications/Processing XXX/lib/
- In the Main.java window that come up, paste in this code and hit the 'Run Main Project button' (its a green play button):

Quote:


package letsp5;
import processing.core.*;

public class Main extends PApplet {
   
   public Main() {
   }
   
   public static void main(String[] args) {
       // must match the name of your class ie "letsp5.Main" = packageName.className
       PApplet.main( new String[]{"letsp5.Main"} );
   }
       
   public void setup () {
       size( 200, 200 );
       background(100);
   }
   
   public void draw () {
       
   }
   
   public void mouseDragged() {
       line(mouseX, mouseY, pmouseX, pmouseY);
   }
   
}




I'm no expert but this works for me. There is also a really good tutorial on using classes (in Eclipse) here: http://www.mostpixelsever.com/tutorial/eclipse

Hope that is useful for someone!
Re: Netbeans and Processing
Reply #1 - Oct 8th, 2007, 5:41pm
 
> Hope that is useful for someone!

yes indeed I found it very helpful Smiley
thank you!
Re: Netbeans and Processing
Reply #2 - Oct 21st, 2007, 5:22pm
 
> Hope that is useful for someone!

Your example helped me to get started with processing along with Netbeans. Thank you very much.
Re: Netbeans and Processing
Reply #3 - Oct 22nd, 2007, 2:03am
 
If your interested in using Open GL with NetBeans:

-  Right click on the 'Libraries' folder in the left hand column and "Add JAR/Folder", then in the dialog box locate the "opengl.jar" & "jogl.jar" files inside Applications/Processing XXX/libraries/opengl/library/

- Right click on the name of the project in the left hand column and select properties. Then in the box that pops up (Project Properties), click on the "Run" link in the left column. In the VM Options field you want to enter:

Quote:

-Djava.library.path="/Applications/Processing XXXX/libraries/opengl/library"
But be sure to change that path to point to the opengl/library folder wherever that may be.

- Lastly you need to add the usual:

Quote:

import processing.opengl.*;
// and
size(200, 200, OPENGL);


Running the application now will work, but if you try and run the compiled JAR of your application from the /dist/ folder, you will find it won't work unless you copy some files into that directory. For Mac you need to copy all the *.jnilib files and for PC it is the *.dll  files from Processing XXXX/libraries/opengl/library/ into the /dist/ folder.

Hope that is useful too!
Re: Netbeans and Processing
Reply #4 - Nov 8th, 2007, 12:46pm
 
I am just gonna keep adding to this post when I find useful Netbeans/Processing stuff.



How to include the processing core inside your JAR.

By default when you add the core.jar to Netbeans and build the project with the code from the first post, it is copied to a /lib/ folder inside the /dist/. If you want to have just a single executable JAR file and distribute that instead of a bunch of folders, all you need to do is add the following line to your build.xml file:

Code:

<target name="-pre-jar">

<unjar src="${file.reference.core.jar}" dest="${build.classes.dir}"/>

</target>


The above code unjars the core.jar to the build directory before netbeans builds your project.
The ${file.reference.core.jar} is a pointer to the core.jar which the project uses. You can find the poniter for the core.jar file (and all other processing libraries you may be using) in the private.properties file. This is found in the nbproject/private folder. This private.properties will have a line something like this:

Code:

file.reference.core.jar=/Applications/Processing XXXX/lib/core.jar


According to this post here: http://forum.java.sun.com/thread.jspa?threadID=664526&messageID=4055062 it is also possible to copy files into the JAR too, using something like:

Code:

<target name="-pre-jar">

<copy file="SomeTextFile.txt" todir="${build.classes.dir}" />
<copy file="AnImageFile.gif" todir="${build.classes.dir}" />

</target>


I haven't tried this myself but it says to use those files, you need to access them like this (where MyClass is the name of the class you're in):

Code:

InputStream in = MyClass.class.getClassLoader().getResourceAsStream("SomeTextFile.txt");

//or

URL url = MyClass.class.getClassLoader().getResource("AnImageFile.gif");
Re: Netbeans and Processing
Reply #5 - Nov 18th, 2007, 4:52am
 
This is a fantastic thread! I'm in a class at Georgia Tech that has been implementing Processing and now we're moving into Java, so I've forwarded on the link to this topic so the people in my class can read about this in case they decide to use NetBeans like I did.
Re: Netbeans and Processing
Reply #6 - Mar 13th, 2008, 4:23pm
 
Has anybody managed to get the video library working with NetBeans yet?

After importing video.jar and QTJava.zip im stuck with an

java.lang.UnsatisfiedLinkError: no QTJava in java.library.path

when the applet is executed.
Re: Netbeans and Processing
Reply #7 - Mar 14th, 2008, 12:32am
 
I just gave it a try now and it worked for me on OS X.
From the error you mentioned it sounds like a it can't find the library at runtime, as opposed to compile time.
You might want to post your code?

After importing the video.jar and the QTJava.zip I used this code from the SlitScan example:
Quote:

package blank;

import processing.core.*;
import processing.video.*;

public class Main extends PApplet {

   Capture video;
   int videoSliceX;
   int drawPositionX;

   public Main() {
   }

   public static void main(String[] args) {
       PApplet.main(new String[]{"blank.Main"});
   }

   public void setup() {
       size(600, 240);

       // Uses the default video input, see the reference if this causes an error
       video = new Capture(this, 320, 240, 30);

       videoSliceX = video.width / 2;
       drawPositionX = width - 1;
       background(0);
   }

   public void draw() {
       if (video.available()) {
           video.read();
           video.loadPixels();

           // Copy a column of pixels from the middle of the video
           // To a location moving slowly across the canvas.
           loadPixels();
           for (int y = 0; y < video.height; y++) {
               int setPixelIndex = y * width + drawPositionX;
               int getPixelIndex = y * video.width + videoSliceX;
               pixels[setPixelIndex] = video.pixels[getPixelIndex];
           }
           updatePixels();

           drawPositionX--;
           // Wrap the position back to the beginning if necessary.
           if (drawPositionX < 0) {
               drawPositionX = width - 1;
           }
       }
   }
}
Re: Netbeans and Processing
Reply #8 - Mar 14th, 2008, 9:53am
 
how to import QTjava.zip?
after install quicktime ,then could i use? nothing else?
Re: Netbeans and Processing
Reply #9 - Mar 14th, 2008, 2:45pm
 
ds wrote on Mar 14th, 2008, 12:32am:
From the error you mentioned it sounds like a it can't find the library at runtime, as opposed to compile time.
You might want to post your code


That's also my guess. But having no Java experience (besides using the PDE) I don't know what to about it.
I'm also using OpenGl so maybe the VM-Option has something to do with it. But I've also tried to change that to the path of the video library without luck.

I'm on Vista using Netbeans 6.0.1.
So here's my test code:

Code:

package CaptureTest1;

import processing.core.PApplet;
import processing.opengl.*;
import processing.video.*;

public class Main extends PApplet {

public static void main(String[] args) {
PApplet.main(new String[]{"CaptureTest1.Main"});
}

public processing.video.Capture cam;

public void setup() {
size(640,480);
background(150);
smooth();
cam = new Capture(this, 320, 240);
}

public void draw() {
fill(0,10,100);
rect(0,0,width,height);

stroke(100,0,30);
strokeWeight(5);

fill(50,20,10,100);

ellipse(mouseX,mouseY,10,10);
}
}


When I run the project I get this error:
Quote:
init:
deps-jar:
compile:
run:
Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: no QTJava in java.library.path
       at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
       at java.lang.Runtime.loadLibrary0(Runtime.java:823)
       at java.lang.System.loadLibrary(System.java:1030)
       at quicktime.jdirect.JDirectLinker$1.run(JDirectLinker.java:266)
       at java.security.AccessController.doPrivileged(Native Method)
       at quicktime.jdirect.JDirectLinker$1$PrivelegedAction.establish(JDirectLinker.java:
264)
       at quicktime.jdirect.JDirectLinker.<clinit>(JDirectLinker.java:272)
       at quicktime.jdirect.QTNative.loadQT(QTNative.java:33)
       at quicktime.jdirect.QuickTimeLib.<clinit>(QuickTimeLib.java:17)
       at quicktime.QTSession.<clinit>(QTSession.java:82)
       at processing.video.Capture.<init>(Capture.java:145)
       at processing.video.Capture.<init>(Capture.java:109)
       at CaptureTest1.Main.setup(Main.java:20)
       at processing.core.PApplet.handleDisplay(PApplet.java:1390)
       at processing.core.PGraphics.requestDisplay(PGraphics.java:690)
       at processing.core.PApplet.run(PApplet.java:1562)
       at java.lang.Thread.run(Thread.java:619)


but it keeps on running -without any visible window or anything. There'S just a progressbar in the lower right corner indicating "CaputeTest1 running". When I stop it it adds this to the Output Window.

Quote:
BUILD STOPPED (total time: 19 seconds)


When I use 'Build Main Project' from the build menu I get this:

Quote:
init:
deps-jar:
Compiling 1 source file to C:\Users\Daniel Kauer\Documents\NetBeansProjects\CaptureTest1\build\classes
compile:
Building jar: C:\Users\Daniel Kauer\Documents\NetBeansProjects\CaptureTest1\dist\netbeans_processing_template.
jar
Copy libraries to C:\Users\Daniel Kauer\Documents\NetBeansProjects\CaptureTest1\dist\lib.
To run this application from the command line without Ant, try:
java -jar "C:\Users\Daniel Kauer\Documents\NetBeansProjects\CaptureTest1\dist\netbeans_processing_template.
jar"
jar:
BUILD SUCCESSFUL (total time: 0 seconds)


running the jar from console yields the same error as above.
Re: Netbeans and Processing
Reply #10 - Mar 15th, 2008, 12:44am
 
I am on a mac so can't help out too much but... to debug this, here is what I would do.

- Firstly have you managed to use the QT Capture in PDE successfully? From memory it is not quite as simple as on a mac.
- I would then try and scrap the OPENGL stuff for now and try and get it working using the default renderer. In your code you are not actually specifying OPENGL in the size() anyway.
- Next I would try check the libraries. Generally I make a copy of them and put them in the lib folder (core.jar etc...). So have a go at doing that, then reimport core.jar, video.jar and the QTJava.zip individually from the lib folder (not the folder itself) using the "Add Jar/Folder" command.
- Also try running the jar created by the build in the Dist folder. It might do the same thing, but it does tend to look/find things differently.

If your code in netbeans is not getting underlined in red, then netbeans has found the libraries. Which means that it is the core itself that is not finding the video library where it expects it to be at runtime.

Good Luck!
Re: Netbeans and Processing
Reply #11 - Mar 15th, 2008, 5:36pm
 
First of all, thank you very much for your support.

ds wrote on Mar 15th, 2008, 12:44am:
- Firstly have you managed to use the QT Capture in PDE successfully From memory it is not quite as simple as on a mac.

QT Capture works in the PDE. But oddly enough it only worky reliably when I specify OpenGl as renderer. If use the standard renderer most of the time no window shows up.
Quote:
- I would then try and scrap the OPENGL stuff for now and try and get it working using the default renderer. In your code you are not actually specifying OPENGL in the size() anyway.

See above. I probably forgot to specify it in the sample, because I've been doing so much trial and error commenting, uncommenting, changing environement variables and so on.
Quote:
- Next I would try check the libraries. Generally I make a copy of them and put them in the lib folder (core.jar etc...). So have a go at doing that, then reimport core.jar, video.jar and the QTJava.zip individually from the lib folder (not the folder itself) using the "Add Jar/Folder" command.

I also did a lot of copying with the .jar files. Which lib folder do you mean Inside of the folder structure of the NetBeans project (there is none at the moment) Or in the lib folder of the JDK This is all kind of confusing because besides the JDK there are 4 other JRE versions in my Java folder and I guess this might also further complicate things. I realize that this is maybe not the right place for these kind of (java specific) questions but I've spent quite some time searching the topic without success. Is there some kind of online documentation regarding the library paths of NetBeans and/or the JVM

Quote:
- Also try running the jar created by the build in the Dist folder. It might do the same thing, but it does tend to look/find things differently.

Yields the same error.

Quote:
If your code in netbeans is not getting underlined in red, then netbeans has found the libraries. Which means that it is the core itself that is not finding the video library where it expects it to be at runtime.


The code is not underlined. I'm convinced that this is just because of a wrong path. If I'm able to run the library with the PDE and also to export a working application it must be possible to use it with NetBeans.
Well, back to more trial & error -and thanks again.
Re: Netbeans and Processing
Reply #12 - Mar 15th, 2008, 7:28pm
 
Success! Unfortunately I'm not completely sure what actually made this work. I think it was the inclusion of

Quote:
C:\Program Files\Java\jdk1.6.0_04\lib\;


to the system PATH environment variable. I also copied QTJava.zip and video.jar there (by now my system is pretty littered with those two files). Restarting is important for the changes to take effect.

Now I'm able to compile the following code and run it from the commandline.
Code:

package nbcapture;

import processing.core.*;
import processing.opengl.*;
import processing.video.*;

public class Main extends PApplet{

public static void main(String[] args) {
PApplet.main( new String[]{"nbcapture.Main"} );
}

Capture cam;

public void setup(){
size(640,480,OPENGL);
smooth();
cam = new Capture(this, 640, 480);
}

public void draw(){
background(150);
if (cam.available() == true) {
cam.read();
image(cam,0,0);
}
ellipse(mouseX,mouseY,20,20);
}

}




Directly running it from Netbeans still produces
Quote:
Error while running applet.
java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: no QTJava in java.library.path


So my guess is NetBeans VM uses a different library path. Is there a way to output this path at runtime?
Re: Netbeans and Processing
Reply #13 - Mar 16th, 2008, 2:56am
 
Sounds like a mess! But at least it works.

It is actually a lot more simple than you think. Each netbeans project has a project folder named with the project name. Inside of that are a bunch of folders:

build - Where the compiled .java files are saved as .class files
dist - Where the compiled executable distribution .jar file gets put
nbproject - Has a bunch of settings for the project
src - The source .java files

What I do, is to make another folder in there called 'lib', then place all the library files (core.jar etc...) there.

Why? Because it is bad form to pollute your java install, and it makes your project self-contained. Basically netbeans uses the project folder as the root directory. So when you add the core.jar to the lib folder like I mentioned, this is the internal link that it keeps:
Quote:
file.reference.core.jar=lib/core.jar

Have a look at the nbproject/project.properties file to see how netbeans is linking to all the .jar files.

In the very first entry on this topic, I said to link directly to the core.jar file in the Processing folder. But have since found this to be a pain, as every time you upgrade Processing it breaks.

The other thing is that the .jar libraries are copied to the 'dist' folder into a folder called 'lib' when you build the project. The compiled .jar file in the dist folder uses the dist folder as it's root - so by having a lib folder in the project folder as well, you keep the two paths identical.

I am not sure about a netbeans class path tutorial, but have a look at this:
http://www.leepoint.net/notes-java/tools/netbeans/netbeans.html
His site is an amazingly useful java reference! More so if you are using pure java, but some stuff is still relevant to processing.
Re: Netbeans and Processing
Reply #14 - Mar 21st, 2008, 5:00pm
 
@dkauer: QTJava definitely needs to be in your system classpath, as does JDK, so that probably *is* what did fix your problem. PDE takes care of this for you, but other IDEs don't, so this isn't specifically a NetBeans thing.

Speaking of NetBeans things, though, I'm generally an Eclipse user but thought I'd give the new NB beta a try, as it looks quite nice. Suddenly I feel like a NetBeans n00b. ;) I can't even get my usual hello, world working.

Quote:
java.lang.ClassNotFoundException: hellop5
       at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
       at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
       at java.lang.Class.forName0(Native Method)
       at java.lang.Class.forName(Class.java:169)
       at processing.core.PApplet.main(PApplet.java:6942)
       at p5.hellop5.main(hellop5.java:13)
Java Result: 1


It's throwing errors in PApplet, not my code. Any ideas? Added my core.jar into libraries and everything.
Pages: 1 2