• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

class path

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic