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

Setting classpath

 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm aware that some form of this question has probably been asked a million times before. However, can someone tell me how I set a classpath from DOS - so that I don't replace my existing classpath?
Why is the classpath subject so complex? It seems you can set different classpaths for different IDEs. Why is this? Do I have to reboot after resetting a classpath from DOS? Are classpaths relevant for both compiling and executing software?
So many questions......
Please help.
Paul
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the confusion gets worse when you don't know what OS one is using.

The answer is different between Win9x and NT/2000
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like most things, something is only complex if you don't understand it fully.
Perhaps it's best to compare classpath to your PATH environment variable on windows. If you want to be able to run programs/commands from the command line in windows, the command shell needs to know where to look for a particular command. For example, a common command is "ping". When you type "ping" the command shell looks for a program named ping.exe in all the directories you have specified in the PATH variable. If you remove the system32 directory from your path and type "ping", the command shell won't be able to locate this prgram, thus won't be able to run it for you.
Classpath is a similar concept in java. It provides a list of directories or jar files that the java tools can look in to find classes or resources. If you ask a java tool, such as javac or just the java.exe program to use a class, but haven't specified *where* to find that class, java can't find it and won't run it or compile it.
Every java tool needs the classpath specified. If you don't manually specify one with the -classpath setting, java tools will try to look at the defined environment variables for one named CLASSPATH and use that value.
So if you try to compile something like:
javac HelloWorld.java
But haven't told the javac program where to find the HelloWorld.java class, you're going to get a error: cannot read: HelloWorld.java.

If you try to run a java class like HelloWorld but don't specify a classpath , you're going to get: Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld.
This is no different than if you try to run a command in the command shell but haven't provide a PATH setting for that command. You'll get an error saying that it is not recognized as an internal or external command,
operable program or batch file.
[ March 04, 2002: Message edited by: Rob Ross ]
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using Windows NT.
When setting a classpath in the options section of an IDE (eg. JBuilder), does this classpath overwrite the system classpath from DOS.
Another thing I don't understand. Isn't it wise to use the '.' as a kind of default classpath? My understanding is that this always considers the current directory as a classpath. If this is the case, why do we have to specify exact paths too?
Thanks for the very helpful response, by the way.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer to the IDE question is totally dependant on the IDE.

Visual Cafe used to stomp your System CLASSPATH, which has in recent years (thankfully - are you listening Oracle and Rational?) become unpopular.

JBuilder (4,5 and 6 anyways) does absolutely nothing to your System CLASSPATH, so adding something to JBuilder will not affect other things on your PC. It doesn't change the classpath on your system, but rather supplies a -classpath parameter to both javac and java.

When I first started with java and was trying to get around the whole path/classpath thing, I found more often than not, having absolutely NO environment entry for CLASSPATH helped me a lot. So unless my memory totally fails, both javac and java will assume '.' is in your CLASSPATH without further prompting from you.

You would still have to specify extra paths, if for example, you had a library of jar files somewhere else on your PC. My own system, I have d:\jars that contains a copy of almost every jar in my system. That way if I'm ever using a text-based editor (Textpad) and I need to add things to my classpath, I can just type "d:\jars\xxxx.jar" and I know it will find it there.
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a piece of code built into the java Toolkit class that checks for any accessibility classes everytime an AWT window appears. If there is something in the accessibility.properties file it will invoke it. Why is it that I have a class in here, which it is unable to see even though I have my classpath set to the directory that my .class file is in? If I put my [I].class[/I/] file into the ext directory of the jdk, it will be seen. The only answer I can come up with, is that the classpath is being changed as my application starts.
Paul
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic