1

I'm on macOS Sierra, FYI.

So I'm trying to set a classpath variable, which has been done using: nano .bash_profile

and I'm able to set the variable as follows:

# setting CLASSPATH for Hello World as a test 
CLASSPATH="/Users/jonvanderlaan/NetBeansProjects/HelloWorld/src/HelloWorld"
export CLASSPATH

# setting PATH for Java 1.8.0
PATH="/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/java:$
export PATH

When I echo the classpath, it shows me the correct classpath. However, when I try to compile and run a .java in that folder, it doesn't work.

javac HelloWorld.java
javac: file not found: HelloWorld.java
Usage: javac <options> <source files>
use -help for a list of possible options

I am attaching a picture of what my directories look like.

Can someone tell me what my problem is here?

(also I'm fairly new to programming and VERY new to the command line. First time posting here. Please be nice!)

(edited to fix problems...still not working)

1 Answer 1

1

javac is the java compiler. try java -jar HelloWorld.jar to run your program.

Sign up to request clarification or add additional context in comments.

6 Comments

I get "Unable to access jarfile HelloWorld.jar"
@vandy Your working directory needs to be where the file is.
what's the output of ls?
@Gendarme I'm not in that directory. I may be misunderstanding the purpose of a classpath. Shouldn't I be able to be in any directory and the compiler searches the classpath when I compile?
@Andbdrew Awesome. So I must be in the correct directory to run the program, but if the program extends classes outside of that package, they must be specified in the classpath. Is that accurate?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.