• 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

Setting PATH and CLASSPATH and why I can't compile anywhere but in the Documents Folder

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

I have gone to Advanced systems Settings --> Environment Variables --> System Variables -->

and put it in both the PATH and CLASSPATH

C:\Program Files (x86)\Java\jdk1.8.0_51\bin

When I try to compile a program using the console in this location it doesn't compile.

However if I try to compile in the C:\Users\person\Documents> it compiles and runs successfully.

Can you tell me why it works in my Documents and not with the paths I put in System Variables.

Thank you,

Scott
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

When you say "it doesn't compile", what are the error messages?

You don't need C:\Program Files (x86)\Java\jdk1.8.0_51\bin in your CLASSPATH.

In general, you have to compile from the top of your project folder. If your source code is in C:\Users\person\Documents and there are no package statements in your program, you would run javac in C:\Users\person\Documents.
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Scott,
Are you putting your .java files in "C:\Program Files (x86)\Java\jdk1.8.0_51\bin" and compile there?
If yes, then I guess "program files" folder is for the OS and should not used by us.
It is recommended to use other locations to store .java/.class files and not to mess with system folders.
Anyway can you post the error you are getting when you are compiling?
 
Scott Treanor
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi and thanks for the help

This is what I entered

C:\Windows\System32>cd C:\Program Files (x86)\Java\jdk1.8.0_51\bin

C:\Program Files (x86)\Java\jdk1.8.0_51\bin>javac Test.java

Test.Java:1: error: error while writing Test" Test.class (Access is denied)
Public class Test
^
1 error

Scott
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is what I thought. Store the Java files in some other location. Preferably in other drive than C:
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is Test.java stored? Try putting it in C:\Users\Scott\workspace then CD to there and execute javac Test.java.

And there's nothing wrong with storing the Java source files on the C drive, IMO.
 
Ranch Hand
Posts: 49
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also go into your terminal and type in

C:\Windows\System32>mkdir Java

That creates a directory named Java on your main drive(C)

Then when I start an individual program I navigate to the directory I just created

C:\Windows\System32>cd Java

And then create a directory for my new program there

C:\Windows\System32>Java mkdir ProgramName

Then you can save that program to that directory using whatever editing software you used to write it, navigate to
it using C:\Windows\System32>cd Java/ProgramName and compile it C:\Windows\System32>Java/ProgramName javac SampleProgram.java

Of course you can enter any name after the mkdir command

There is no reason that that shouldn't compile unless there is an issue in your code

Hope that helps a little!
 
reply
    Bookmark Topic Watch Topic
  • New Topic