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 › Running from command line (Using Eclipse)
Page Index Toggle Pages: 1
Running from command line? (Using Eclipse) (Read 1936 times)
Running from command line? (Using Eclipse)
Apr 16th, 2010, 9:57pm
 
Hello everyone, Processing newbie here.

I'm trying to make something in Eclipse right now (with Proclipsing), but I'd like to be able to run it from the command line. I've got a very simple class set up:
Code:
import processing.core.PApplet;

public class MainClass extends PApplet{

public void setup() {
println("foo");
}

public void draw() {
}

public static void main(String[] args) {
PApplet.main(new String[] { MainClass.class.getName() });
}
}

So now I have a bin folder with a MainClass.class in it. In the command prompt, I cd to that bin folder and run
Code:
java -cp . MainClass 


which gets me
Code:
Exception in thread "main" java.lang.NoClassDefFoundError: processing/core/PApplet
       at java.lang.ClassLoader.defineClass1(Native Method)
       at java.lang.ClassLoader.defineClassCond(Unknown Source)
       at java.lang.ClassLoader.defineClass(Unknown Source)
       at java.security.SecureClassLoader.defineClass(Unknown Source)
       at java.net.URLClassLoader.defineClass(Unknown Source)
       at java.net.URLClassLoader.access$000(Unknown Source)
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
Caused by: java.lang.ClassNotFoundException: processing.core.PApplet
       at java.net.URLClassLoader$1.run(Unknown Source)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
       at java.lang.ClassLoader.loadClass(Unknown Source)
       ... 12 more
Could not find the main class: MainClass.  Program will exit.

I'm pretty stumped. I've been trying for a long time now to get this to work. For what it's worth, I ran "java -cp . MainClass" just fine when I took out the Processing import statement and such from the class, but I can't get it to work with Processing.

Sorry if this is in the wrong forum or I forgot something. I'm a little exhausted right now.
Re: Running from command line? (Using Eclipse)
Reply #1 - Apr 17th, 2010, 2:43am
 
-cp option is to specify classpath.
You have to provide the path to core.jar in this classpath.
Re: Running from command line? (Using Eclipse)
Reply #2 - Apr 17th, 2010, 6:35am
 
OH MAN, IT WORKS. Thanks a lot Phil!

So it turns out was all my fault. "java -cp .\core.jar;. MainClass" got it working. I must've forgotten to include the ";." before. Also, there's a copy of core.jar in my bin folder.
Page Index Toggle Pages: 1