File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Running a java file through the command line Vs IDE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Running a java file through the command line Vs IDE" Watch "Running a java file through the command line Vs IDE" New topic
Author

Running a java file through the command line Vs IDE

Ravaa Bal
Ranch Hand

Joined: Apr 15, 2009
Posts: 31
Hi all,

I'm trying to run some example code provided by jsresources, http://www.jsresources.org/examples/SynthNote.html. It states that this code needs to be run by typing in a line in the command prompt in the form of:

java SynthNote <keynumber> <velocity> <duration>
(where the last three words are parameters)

The thing is, this doesn't work for me. I get a "could not find the main class" error. For the record, I set the directory of the command prompt to the folder where the java file is located using "cd <dir/dir/etc>" before typing in the above line.

With this in mind, I attempted to run this code in the Netbeans IDE but this returns:
SynthNote: usage:
java SynthNote [<channel>] <note_number> <velocity> <duration>
Java Result: 1
BUILD SUCCESSFUL (total time: 4 seconds)


So it was successful, but not only did I not hear a note sound as I was meant to but I also wasn't given a choice to input the parameters...

Would anyone happen to know what I could be doing incorrectly here? Any insight would be great.

Thank you.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11160
    
  16

you don't need to be in the directory where the .java file is. You need to be in the directory where the .class file is.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ravaa Bal
Ranch Hand

Joined: Apr 15, 2009
Posts: 31
Aha silly me, thank you.

Is it possible to run something like this on Netbeans and be able to enter parameters when testing? As opposed to using the command line...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
The IDEs all have special windows where you enter the parameters. As a beginner you would usually be better using the command line.
Ravaa Bal
Ranch Hand

Joined: Apr 15, 2009
Posts: 31
Fair enough, thanks for your input!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running a java file through the command line Vs IDE
 
Similar Threads
Velocity Error:Resource Not Found Exception
Executable Java program
Problem compiling servlet [RESOLVED]
made my java code as service. will this service make use of the command prompt?
Use cmd and not an IDE.