Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to run a java class in console

 
peter tong
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class in directory c:\Workspace\RegExTest\bin\RegexTestHarness.class

if I go to directory c:\Workspace\RegExTest\bin and then type
java RegexTestharness
the class can be run successfully.

but if I run in another place and try to run like
java c:\Workspace\RegExTest\bin\RegexTestHarness
or
java -cp c:\Workspace\RegExTest\bin\RegexTestHarness

both return error, so what is the correct syntax to run the class without go to its directory first?
Also, if run in eclipse, there is error "No console."
the class is just copy from tutorial as follow:
 
Thakur Sachin Singh
Ranch Hand
Posts: 248
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set classpath variable for javac and java command .

for this set PATH=C:\Program Files\Java\jdk1.6.0\bin;

now you can compile and run the file on windows machine.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try a command like:

java -cp c:\Workspace\RegExTest\bin RegexTestHarness

Note that the parameter to the -cp is the directory that contains the class file (c:\Workspace\RegExTest\bin). After that is a space, and then the class name.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic