• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Scott Treanor
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • 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
  • 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: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • 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: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Franklin Marquette
Ranch Hand
Posts: 49
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • 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!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!