Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java in General  RSS feed

 
Surya Prabhavathi Akella
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a beginer in java.
why do we need to set the calsspath?
why we need to set environment variables even if we are setting the class path everytime
 
Srikanth Ramu
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When your class uses third party or user defined classes/jars you need to tell java where these classes are available. Hence you need to set the classpath. Either you can set it in command line like "javac -classpath <Path> ......" or set the environment variable "set CLASSPATH=........".
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"why do we need to set the calsspath?"

The classpath is where Java looks for class files to load and execute. You have to tell Java where to look for class files.

"why we need to set environment variables even if we are setting the class path everytime"

You do not need to set environment variables if you specify the classpath on the command line with the "-cp" or "-classpath" switch.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if this clears things up or raises more questions. Follow the link to Sun's Setting the Classpath too.
 
Shawn Vader
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Environment variables and setting the classpath have a similar effect i.e. the compiler and the virtual machine (vm) look in these areas for classes that your code is referencing. When you are working in an ide like eclipse for example you add your third party libraries normally jar files to the libraries in the path settings tab. This has the same effect as adding them to your classpath. This is helpful but can be confusing when you want to run your application outside of your ide as you will have to set the classpath yourself. Tip: When you run you class in your idea the first line in the output window will be the execute command for the class you are running with the full �classpath so you can see the full classpath that the ide is using to execute your class.

Try to use environment settings as little as possible as they are specific to the machine that you are running on. If you get ClassNotFoundExceptions for code you have not written it means that some classes can�t be found in the classpath or the environment variables. You will have to find the jars and download them and add them to your classpath, if you are in an idea this will be to the libraries tab. If you don�t know what jars the classes are in you can get an idea using some of the jar search sites like jarhoo.com costs or a free one http://www.whatjar.co.uk where you search on the missing class and they tell you what jar file the class is in.

Hope this helps in some way:
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!