• Post Reply Bookmark Topic Watch Topic
  • New Topic

class path  RSS feed

 
Guy Belpa
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one of my friend did something like this

\>java -cp . <classname>

what does that mean?
what are other ways for setting & run a java class?
 
Vinay Belagavi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java -cp is used for class search path of directories..you can go to System Properties-->Advance-->Environments variables and add "C:\Program Files\Java\jdk1.5.0_06\bin" path in the path variable. Check the version of jdk you have.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vinay Belagavi:
java -cp is used for class search path of directories..you can go to System Properties-->Advance-->Environments variables and add "C:\Program Files\Java\jdk1.5.0_06\bin" path in the path variable. Check the version of jdk you have.


Argh! PATH != CLASSPATH

Original Poster: there are other ways of running a Java Program, but I think messing with the CLASSPATH environment variable is one of the worst. Two better ways are:

1. Zipping your code into an executable JAR file. (You can google that)
2. Using Ant.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Guy Belpa:
one of my friend did something like this

\>java -cp . <classname>

what does that mean?
what are other ways for setting & run a java class?


The "-cp" option allows you to specify the classpath on the command line. I guess you know what the classpath is, if not, read this: How Classes are Found.

The "." (dot) represents the current directory.

So "java -cp . MyClass" means: run the class MyClass, and look in the current directory for class files.

Normally you should not set the CLASSPATH environment variable, and you don't need the "-cp ." because Java will look for class files in the current directory by default.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!