• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to set classpath in java?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to know how to set classpath in java.I have installed SDK 1.5.0.So can someone guide me about it?
 
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
You don't need to set the classpath, unless your Java program needs classes that are not in the current directory. If you're for example using classes in a third-party JAR file, then use "-cp" or "-classpath" options on the command line to include those classes in the classpath.

To compile:
javac -cp SomeJarFile.jar;. MyProgram.java

To run:
java -cp SomeJarFile.jar;. MyProgram
 
Ranch Hand
Posts: 630
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jesper Young tells us very right answer, but i think this way is to write every time at compilation & running of program.But i think you can set class path which will be third party but you needed your certain program, in System properties.If you using WinXP then In
System properties-->Advanced-->Environment Variables
set variable as class path & Value as your desire jar file's lib path.
Then i think you should not write every time

To compile:
javac -cp SomeJarFile.jar;. MyProgram.java

To run:
java -cp SomeJarFile.jar;. MyProgram

.
Try this.
 
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to set the classpath permanently; in fact if you do it will gradually become cluttered with unnecessary folder references.
You can repeat the line with the up and down arrows on command prompt or a shell. There is probably some way you can write something which will set the classpath for your session. I did a Google search and this came up first. Those instructions appear to apply to pre-XP Windows� but will probably work on XP too.
 
reply
    Bookmark Topic Watch Topic
  • New Topic