0

I want to add the java-servlet-api.jar to the classpath variable.

export CLASSPATH=/.../java-servlet-api.jar

adds the class path to only one session of the terminal. How do I permanently add this to CLASSPATH?

I looked at a few links which asked me to modify the bashrc file, but I am unable to locate it on EL Capitan. Can someone help me with this?

Sahitya Sridhar
  • 119
  • 3
  • 10
  • 1
    Possible duplicate of [Adding to the classpath on OSX](http://stackoverflow.com/a/1676261/1248974) – chickity china chinese chicken Sep 01 '16 at 16:40
  • 5
    Possible duplicate of [Adding to the classpath on OSX](http://stackoverflow.com/questions/1675765/adding-to-the-classpath-on-osx) – talex Sep 01 '16 at 16:41
  • Mac OS doesn't automatically make those user config files like `~/.bashrc` and `~/.bash_profile`, you have to manually create them - From a Terminal shell type `touch ~/.bashrc` then edit and add your `export`s lines. [How can I create bash_profile and bashrc](http://apple.stackexchange.com/a/219206). However, as Thomas Arnaud stated, and also in my experience, Mac doesn't do a good job detecting `.bashrc` so I've added exports to `~/.bash_profile` and works well. – chickity china chinese chicken Sep 01 '16 at 16:58

2 Answers2

1

You choose 1 of 2 solutions below:

Solution 1: Open Terminal, then type:

export CLASSPATH=$CLASSPATH:/path/to/file/java-servlet-api.jar

then:

source .bash_profile

Solution 2: Open terminal, type command:

vim ~/.bash_profile

you will see something like this:

enter image description here

press i, add your file to classpath like sample.

then, press esc, type :wq, then return

Make effective: don't need restart, type:

source .bash_profile
Vy Do
  • 46,709
  • 59
  • 215
  • 313
0

By default, I am not sure that Mac OS terminal launches the .bashrc file. But it launches the .profile for sure.

Open a new terminal and launch this command :

echo 'export CLASSPATH=/.../java-servlet-api.jar' >> $HOME/.profile

Then open a new terminal and your environment variable should be ok.

Thomas Arnaud
  • 448
  • 5
  • 16