Can anyone tell me how to add to the classpath on OSX?
If you want to make a certain set of JAR files (or .class files) available to every Java application on the machine, then your best bet is to add those files to /Library/Java/Extensions.
Or, if you want to do it for every Java application, but only when your Mac OS X account runs them, then use ~/Library/Java/Extensions instead.
EDIT: If you want to do this only for a particular application, as Thorbjørn asked, then you will need to tell us more about how the application is packaged.
In OSX, you can set the classpath from scratch like this:
export CLASSPATH=/path/to/some.jar:/path/to/some/other.jar
Or you can add to the existing classpath like this:
export CLASSPATH=$CLASSPATH:/path/to/some.jar:/path/to/some/other.jar
This is answering your exact question, I'm not saying it's the right or wrong thing to do; I'll leave that for others to comment upon.
If you just want to use a class path just for the current run time. You can achieve that by add a class path option when you run java command.
In you command line. Use
java -cp "path/to/your/jar:." main
rather than just
java main
By doing so, your command tells the process class paths where it can search for libraries.
If your shell is tcsh or csh, you can set it in /etc/profile. Open terminal, "vim /etc/profile" and add the following line:
setenv CLASSPATH (insert your classpath here)
Normally there's no need for that. First of all
echo $CLASSPATH
If there's something in there, you probably want to check Applications -> Utilites -> Java.
来源:https://stackoverflow.com/questions/1675765/adding-to-the-classpath-on-osx