• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Classpath and JAVA_HOME doubt

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends,

I have read in the K & B Book that we can set the default classpath in an Operating system environment variable
how to do this in windows XP..??

Why does one create and set JAVA_HOME enviroment variable..??

Can anyone please give their suggestions on the above problem.Thank you in advance.


Regards,
Hardik.S.Raja
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Windows XP:

Click Start Button >> Control Panel >> System >> Advanced tab >> Click Environment Variable button >> One dialog box appears, just do the changes you
want for classpath and so.

Remember when you type javac or java from the command line, it path setting is
given in PATH system variable. Address to your directories containing your packages is given in the classpath setting.
 
Hardik Raja
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean to say, If I want to include some directory to be in the default classpath, I should add that directory path in PATH environment variable in Windows..? correct ?

Why does one create and set JAVA_HOME enviroment variable..??

Thanks
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hardik Raja:
You mean to say, If I want to include some directory to be in the default classpath, I should add that directory path in PATH environment variable in Windows..? correct ?

Why does one create and set JAVA_HOME enviroment variable..??

Thanks




When did I say so?
"classpath" environment variable keeps the address to the directories where your packages are stored. Don't ever mention the name of the package there.
I must be the address till the top level directory inside which the package(s) is/are stored. Not even / or \. eg. "c:\programs\classes" is correct.

"c:\programs\classes\" or "c:\programs\cert" etc. are incorrect
Note: cert is a package
 
Hardik Raja
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK I got what you explained...

but If I am including some directory path

eg. c:\hardik (note hardik is a directory) in PATH environment variable

and hardik contains one package p1 which contains a class file animal
i.e p1.animal which I require in test.class

If I exceute using java test...it give the following runtime error..

Exception in thread "main" java.lang.NoClassDefFoundError: p1/animal
at p2.test.main(test.java:9)


and If I execute using overriding classpath say....

java -cp \hardik;. test

..It Executes perfectly..

Why is the default classpath not able to find animal class(p1.animal) ?

Thanks
 
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hardik Raja:
OK I got what you explained...

but If I am including some directory path

eg. c:\hardik (note hardik is a directory) in PATH environment variable

and hardik contains one package p1 which contains a class file animal
i.e p1.animal which I require in test.class

If I exceute using java test...it give the following runtime error..

Exception in thread "main" java.lang.NoClassDefFoundError: p1/animal
at p2.test.main(test.java:9)


and If I execute using overriding classpath say....

java -cp \hardik;. test

..It Executes perfectly..

Why is the default classpath not able to find animal class(p1.animal) ?

Thanks



JAVA_HOME is used to store the directory where you installed java (so you don't have to hardcode the actual locations into your scripts and also so other programs can find the location of the JVM.

The PATH and CLASSPATH variables are not the same.

You set the PATH environment variable to tell the operating system where to find the java and javac commands. Typically this is JAVA_HOME\bin. If you dont do this you will see an error

'java' is not recognized as an internal or external command, operable program or batch file.


You set the CLASSPATH environment variable to tell the java javac commands where your classes and packages are stored. ie CLASSPATH="c:\hardik;."

The . means that it also looks in the current working directory for classes and packages.
 
Hardik Raja
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I got it......

The PATH and CLASSPATH variables are not the same.



It was here, where I was making a mistake..I was thinking PATH and CLASSPATH were same..Thanks


If we dont define CLASSPATH as an Environment variable

as CLASSPATH="c:\hardik;."

which locations are searched for classes and package..

Eg for java test or javac -d . test.java


Thanks....
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,
I read all as what I having a sample problem.
I put path in system_environment and then see path correctly. This is for all jars which contains some importing in my source.

Even though set it correctly, I can not compile my source with import....
the compiler can not recognize any .my jar files from where all jar are like c:\lib
My source is c:\int\source

I used the command like javc mysource.java in c:\int\source

how to fix it and what's problem is.

please answer for me.

cheers,
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Even though set it correctly, I can not compile my source with import....
the compiler can not recognize any .my jar files from where all jar are like c:\lib
My source is c:\int\source

I used the command like javc mysource.java in c:\int\source

how to fix it and what's problem is.



You have to give the name of the jar file "xyz.jar" there in the classpath
with the path to that xyz.jar.

Otherwise you .jar file can only be recognized/can be used without this,
when you place them to the default location that is "jre/lib/ext".
javac and java automatically find it from that location.


Thanks,
 
please buy my thing and then I'll have more money:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic