vandy
vandy

Reputation: 75

Can't run java program using classpath variable from terminal

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)

Upvotes: 1

Views: 421

Answers (1)

Andbdrew
Andbdrew

Reputation: 11895

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

Upvotes: 1

Related Questions