• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

set the System variable "Path" in windows 10

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I have "C:\misClases" directory, and inside this, I have the directories "packagea" and "packageb". In packagea I have ClassA and in packageb I have ClassB.

Since my Command line I type:

cd C:\misClases

javac packagea\ClassA.java   packageb\ClassB.java   ->    (the .class files are made).

Then Being in misClases Directory I type:

java packageb.ClassB  -> and I get: "error: could not find or load main class packageb.ClassB".

Then I type:

java -cp C:\misClases    packageb.ClassB   -> And I get the program output: "Got it"

Could anyone tell me what I have to do to write in my Command line: "java   packageb.ClassB" and that  it works without problem?

I think The problem is with the System variable "Path".

I have attached the Command line output.

Thanks for all!!!.


cmd.PNG
[Thumbnail for cmd.PNG]
 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check in your environment variables and see if you have a CLASSPATH defined.
If so then that would be the problem.
 
jose laguia
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have already defined in the variable "path" the java sdk bin directory and misClases directory: C:\Program Files\Java\jdk1.8.0_141\bin; C:\misClases. But I don't know where the problem is.
path.PNG
[Thumbnail for path.PNG]
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave asked if you have a "CLASSPATH" variable - that is completely different than a "PATH" variable...
 
jose laguia
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I don't have a CLASSPATH variable!!!
 
jose laguia
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please what do I have to do?
 
jose laguia
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please what do I have to do?
 
Rancher
Posts: 5114
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Open a command prompt and enter:
SET

All the environment variables will be shown.
 
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jose laguia wrote:No I don't have a CLASSPATH variable!!!


That's okay, if you're sure you don't have a CLASSPATH variable, then that's not the problem.

If you want to double check, go to the command line and type

   echo %classpath%

If all that is displayed on the screen is %classpath% then you have no CLASSPATH variable set.  Again, that's fine.

If anything else is displayed, copy and paste it here.

EDIT: Even better, type

   set CLASSPATH

and it will display either the contents of CLASSPATH, or give you a nice message saying the environment variable is not set.
 
Knute Snortum
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jose laguia wrote: I have already defined in the variable "path" the java sdk bin directory and misClases directory: C:\Program Files\Java\jdk1.8.0_141\bin; C:\misClases. But I don't know where the problem is.


You don't need C:\misClases in your PATH variable unless there are executables in that folder that Windows needs to find.  Java doesn't use the PATH variable to find classes.
 
jose laguia
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If you want to double check, go to the command line and type

   echo %classpath%

If all that is displayed on the screen is %classpath% then you have no CLASSPATH variable set.  Again, that's fine.

If anything else is displayed, copy and paste it here.

EDIT: Even better, type

   set CLASSPATH

and it will display either the contents of CLASSPATH, or give you a nice message saying the environment variable is not set.



Hello I'm sorry I couldn't answer the posts.

I checked if I had CLASSPATH variable and I don't have.

If I set CLASSPATH variable then in this variable Do I have to lay the paths of the .class files or .jar archives related to the classes I use in my java aplication?

Thanks for everything. You are helping me a lot.
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jose laguia wrote:
I checked if I had CLASSPATH variable and I don't have.



If you don't have a CLASSPATH variable set, then you should be seeing what you are seeing. Either (1) you need to compile from the C:\misClases directory, or (2) use the -cp option to specify the C:\misClases directory. Compiling from any other directory, and without the -cp option, will fail if the compiler needs a class definition that is used.

jose laguia wrote:
If I set CLASSPATH variable then in this variable Do I have to lay the paths of the .class files or .jar archives related to the classes I use in my java aplication?



You need to have the path to the top (ie. root) of the class files. In this case, it is the C:\misClases directory. You do not need to specify the packagea or packageb directories because those are part of the package.

As for the jar files, either (1) you need to specify the complete path and name of the jar files, or (2) the directory where the jar files reside (with a "*" included).

Henry
 
jose laguia
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. thanks for everything. I understand. It works from C:\misClases without -cp and any other directory I have to indicate the path. I don“t use jar files yet :-).
cmd1.PNG
[Thumbnail for cmd1.PNG]
 
reply
    Bookmark Topic Watch Topic
  • New Topic