Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access is denied while compiling Java on Windows

I created two java files: Pizza.Java and PizzaOrder.Java.

I tried compiling my code using javac in the command prompt like this:

javac pizzaorder.java

I am getting access is denied error:

C:\Users\Meutex>cd\

C:\>cd "Program Files\Java\jdk1.7.0\bin"

C:\Program Files\Java\jdk1.7.0\bin>javac PizzaOrder.java
PizzaOrder.java:23: error: cannot find symbol
                Pizza order = new Pizza ();
                ^
  symbol:   class Pizza
  location: class PizzaOrder
PizzaOrder.java:23: error: cannot find symbol
                Pizza order = new Pizza ();
                                  ^
  symbol:   class Pizza
  location: class PizzaOrder
2 errors

C:\Program Files\Java\jdk1.7.0\bin>javac Pizza.java
Pizza.java:11: error: error while writing Pizza: Pizza.class (Access is denied)
public class Pizza {
       ^
1 error

C:\Program Files\Java\jdk1.7.0\bin>javac Pizza.java

What am I doing to cause this error?

like image 968
Mad coder. Avatar asked Oct 23 '11 08:10

Mad coder.


People also ask

Why is my Java program not compiling?

It means that javac.exe executable file, which exists in bin directory of JDK installation folder is not added to PATH environment variable. You need to add JAVA_HOME/bin folder in your machine's PATH to solve this error. You cannot compile and run Java program until your add Java into your system's PATH variable.


2 Answers

It appears that you're trying to put your source files in the system C:\Program Fiels\Java\jdk1.7.0\bin directory. Try making your own directory for your source files (under your own home directory), instead of putting them in the system path. You probably don't have permissions to write to that directory (but I'm not sure how you got your source files there).

like image 195
Greg Hewgill Avatar answered Oct 25 '22 16:10

Greg Hewgill


The Access Denied error is most likely due to the fact that you're trying to compile this program within the jdk directory, which is inside \Program Files, which is NOT universally writeable by users. You should be doing your coding elsewhere (perhaps in your My Documents directory, or at least somewhere you've got write permissions).

like image 39
Marc B Avatar answered Oct 25 '22 15:10

Marc B