Okay, I figured it out.
How to use javax.vecmath
in Mac OS(11.5.1) with Java(16.0.2)
I am giving a description that sort of includes why I do things, skip to the TLDR at the bottom if you just want an answer.
Step 1: Download the latest version of Java3D
This contains vecmath
, along with j3dcore
and j3dutils
. It will download a .zip file. Unzip the file and it will expand into a new directory with another .zip file inside, j3d-jre.zip
. Unzip j3d-jre.zip
and it will expand into a directory lib. Inside lib will be a subdirectory, ext, with three .jar files inside: j3dcore.jar
, j3dutils.jar
, and vecmath.jar
. You can put these literally anywhere, just make sure you keep track of their location (I put them in ~/Library/Java/Extensions, this location is on the hard drive and will need an admin password to do anything–use
sudo unzip /path/to/j3d-jre.zip
if you are doing things in shell). You CAN put the ext
directory in JAVA_HOME/lib/
but after Java 6, this will cause a problem.
Step 2: Change CLASSPATH
Java has no idea how to find vecmath.jar
so you have to specify it.
Option 1: Specify CLASSPATH
with every shell command
The simplest version is using
javac -cp ".:/path/to/vecmath.jar:" MyMainProgram.java
to compile and
java -cp ".:/path/to/vecmath.jar:" MyMainProgram
to run the program (you can also replace -cp
with -classpath
and it will do the same thing)
This option won't ever destroy your CLASSPATH
but you also have to include the -cp
command every time you compile and run a program that imports javax.vecmath
.
Option 2: Specify CLASSPATH
with every new terminal window
A little more lasting than -cp
, you can define CLASSPATH
such that any changes will only take place in that terminal window. Use this form:
export CLASSPATH=".:/path/to/vecmath.jar:"
Now when you call
javac MyMainProgram.java
java MyMainProgram
Java will see that CLASSPATH
is .:/path/to/vecmath.jar
and everything will compile and run without adding the -cp
command.
The main downside of this option is that if you update CLASSPATH
again, you have to remember to add the previous CLASSPATH
(which you can see at any time with echo $CLASSPATH
)
Option 3: Permanently add CLASSPATH
to terminal
Enter the following into terminal:
open ~/.bash_profile
this will open a window that may or may not have code in it. Regardless of any pre-existing code, scroll to the bottom and add
export CLASSPATH=".:/path/to/vecmath.jar:"
This option holds the CLASSPATH
in all terminal windows forever or until you change it (using any method above).
TLDR
Download Java3D for macOS
Unzip java3d-1_5_1-macosx.zip
and open the directory it creates
Unzip j3d-jre.zip
and open the new directory /lib/
and the subdirectory /lib/ext/
Move vecmath.jar
, j3dcore.jar
, and j3dmath.jar
to ~/Library/Java/Extensions (this requires an admin password) or any other location
Run the following line in terminal:
open ~/.bash_profile
Go to the bottom and add the following:
export CLASSPATH="/path/to/vecmath.jar:$CLASSPATH"
import javax.vecmath.*
to any .java program you want