title: Why does a jar file have no permissions to read from disk when started via double-click - but not if started from the Terminal?
body: <p>On a MacBook Pro (2015) with fresh-installed Big Sur and AdoptOpenJDK 11 I developed a Java program for educational purpose that uses the JFileChooser. I did not use any IDE-specific code. As the rest of the program does not matter, here is a minimum-example that produces the same problem for me (Note: Here only as an example, clicking the button will open the File Chooser, choosing a file and clicking OK will change the button's text to 'OK'):</p>
  <pre><code>import javax.swing.*;
  import java.awt.event.*;
  
  public class Test extends JFrame implements ActionListener {
  
    private JFileChooser jf;
    private JButton jb;
  
    public Test() {
      setSize(480,320);    
      jf = new JFileChooser();
      jf.setDialogType(JFileChooser.OPEN_DIALOG);
      jb = new JButton(&quot;CLICK ME&quot;);
      jb.addActionListener(this);
      add(jb);
      setVisible(true);
    }
  
    public void actionPerformed(ActionEvent e) {
      if (e.getSource().equals(jb)) {
          jf.setVisible(true);
          final int result = jf.showOpenDialog(null);
          if (result == JFileChooser.APPROVE_OPTION) {
            jb.setText(&quot;OK&quot;);
          }
      }
    }
  
    public static void main(String[] args) {
        new Test();
    }
  }
  </code></pre>
  <p>If I start the program <strong>via Terminal</strong> (<code>java Test</code> or compiled as a jar with <code>java -jar Test.jar</code>) <strong>everything works fine</strong>. I can open the File Chooser and it shows up my files and folders on my disk.</p>
  <p>If I start the compiled <strong>jar via double-click</strong>, the program launches as well, but if I open the File Chooser <strong>I cannot see any files on my disk</strong> and hence I cannot load and save data to disk.</p>
  <p>As I only have these problems on my Mac (not on Windows 10 or Lubuntu Linux) this might be a very specific problem due to false Java settings on my Mac. However, as I installed a fresh copy of Big Sur and AdoptOpenJDK 11 for Mac without changing anything, I wonder if this problem may occur for other people who want to run my program (teachers and students).</p>
  <p>So what might be the problem and how to solve this (for me and potentially others)?</p>
  <p><em>I already figured out with the activity monitor that the double-clicked jar is loaded with the JavaLauncher (but I cannot find it on disk and I cannot change any system settings for that).</em></p>
  <p><em>I also searched for similar problems here. But these were mostly associated with saving files on wrong paths.</em></p>
  <p>Would be nice to find a solution. Thank you for answering!</p>