java.io.FileNotFoundException: (Operation not permitted) error with ./keytool -import on mac osx (el capitan) - Java 6

This seems to be a mac specific issue when the exception states (Operation not permitted) -

For anyone else having this problem you need to reboot your mac and press ⌘+R when booting up. Then go into Utilities > Terminal and type the following commands:

csrutil disable
reboot

You should be able to import cacerts to your Java keystore following that. Don't forget to reenable csrutil after you've imported that cacert. Reboot, press ⌘+R when booting up, Utilities > Terminal, enter:

csrutil enable
reboot

I was hit by similar issue on MacOS Big Sur while starting an jnlp file:

CouldNotLoadArgumentException[ Could not load file/URL specified: /Users/jhartman/Documents/Favorities/NCC/NCC 123.jnlp]
....
Caused by: java.io.FileNotFoundException: /Users/jhartman/Documents/Favorities/NCC/NCC 123.jnlp (Operation not permitted)

Solution for this was:

  • Give Java (/usr/bin/java) Full Disk access
  • Give Java (/usr/bin/java) Files and Folders access to Downloads, Documents and Folders

Steps

  1. Open /usr/bin in Finder, e.g. by invoking from Terminal:
jhartman@MBP ~ % open /usr/bin
  1. Localise java (and keytool)

  2. Open System Preferences and Security & Privacy. Open Full Disk Access tab and authorise

  3. Drag java and keytool from Finder window opened in step 1 and drop onto the App list in Full Disk Access

enter image description here

  1. Go to Security & Privacy -> Files and Folders, tick Downloads Folder and Document Folder for java and keytool

enter image description here

It was solution for my problem but I hope it should also sort out keytool issue.