david garcia
david garcia

Reputation: 1

Java directory pathway

I wanted to start learning Java but I am a bit confused as to how to set the path correctly. I want to make a directory in my home directory for all my java programs so I was thinking something like:

/home/user/Java_Projects

but I'm not sure how to make the symbolic link to it. Would it be something like this?:

ln -sf /usr/local/jdk-11/bin/java /usr/local/bin/java/Java_Projects

Also, in this case what happens with javac? Does it then become:

ln -sf /usr/local/jdk-11/bin/javac /usr/local/bin/javac/Java_Projects

A strange thing that I've noticed is that when I run the code in my home directory (/home/user) everything works fine but then when I try to run the code from my java directory by changing to /home/user/Java_Projects it won't work anymore and I have no idea why.

The only thing I can think of is some kind of permission error because this is what I get:

error: error while writing HelloWorld: /home/user/Java_Projects/HelloWorld.class

Thanks in advance!

Upvotes: 0

Views: 121

Answers (1)

stdunbar
stdunbar

Reputation: 17475

You're confusing the JDK tools (java, javac, etc) with the coding side. You will need to add /usr/local/jdk-11/bin to your PATH environment variable. Since you're in a Unix based environment you'll want to add that in your .bashrc or the equivalent for your shell. Something like:

export PATH=/usr/local/jdk-11/bin:$PATH

You normally have to start a new shell (i.e. the command line window) or log out and back in for that to take effect. Then, in your Java_projects directory you can simply run:

javac HelloWorld.java

You should have write permission in the Java_projects already assuming that it's in your home directory. If not, run chmod 755 Java_projects from the /home/user directory. The user in this case should be your login name to the operating system.

Upvotes: 1

Related Questions