title: WARNING: An illegal reflective access operation has occurred (portable opencv in java)
body: <p>I want to make a portable <code>opencv</code> application which the dependency is added to maven file <code>pom.xml</code>. </p>
  
  <p>Simplified code is :</p>
  
  
  
  <pre><code>import org.opencv.core.Mat;
  
  public class Builder {
  
      public static void main(String[] args) {
  
          nu.pattern.OpenCV.loadShared();
          System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
  
          Mat mat = new Mat(4,3,1);
          System.out.println(mat.dump());
      }
  }
  </code></pre>
  
  <p>I added this to <code>pom.xml</code>:</p>
  
  <pre><code>&lt;dependency&gt;
        &lt;groupId&gt;org.openpnp&lt;/groupId&gt;
        &lt;artifactId&gt;opencv&lt;/artifactId&gt;
        &lt;version&gt;3.2.0-0&lt;/version&gt;
        &lt;scope&gt;compile&lt;/scope&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>It works with the following warning <strong>for java 9</strong>:</p>
  
  <pre><code>WARNING: An illegal reflective access operation has occurred
  WARNING: Illegal reflective access by nu.pattern.OpenCV$SharedLoader (file:/home/martin/.m2/repository/org/openpnp/opencv/3.2.0-0/opencv-3.2.0-0.jar) to field java.lang.ClassLoader.usr_paths
  WARNING: Please consider reporting this to the maintainers of nu.pattern.OpenCV$SharedLoader
  WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
  WARNING: All illegal access operations will be denied in a future release
  Java HotSpot(TM) 64-Bit Server VM warning: You have loaded library /tmp/opencv_openpnp6598848942071423284/nu/pattern/opencv/linux/x86_64/libopencv_java320.so which might have disabled stack guard. The VM will try to fix the stack guard now.
  It's highly recommended that you fix the library with 'execstack -c &lt;libfile&gt;', or link it with '-z noexecstack'.
  101, 115,  47;
   108, 105,  98;
    47, 108, 105;
    98, 111, 112]
  </code></pre>
  
  <p><strong>UPDATE:</strong> And the following warning for java 8:</p>
  
  <pre><code>Java HotSpot(TM) 64-Bit Server VM warning: You have loaded library/tmp/opencv_openpnp3835511967220002519/nu/pattern/opencv/linux/x86_64/libopencv_java320.so which might have disabled stack guard. The VM will try to fix the stack guard now.
  It's highly recommended that you fix the library with 'execstack -c &lt;libfile&gt;', or link it with '-z noexecstack'.
  </code></pre>
  
  <p>Collapsing the opencv jar in maven dependency folder shows that all the libraries are in grayed color as depicted here:</p>
  
  <p><a href="https://i.stack.imgur.com/AtA2A.png" rel="noreferrer"><img src="https://i.stack.imgur.com/AtA2A.png" alt="maven dependency folder for opencv 3.2"></a></p>
  
  <p>What if I ignore this warning and don't link the libraries with the mentioned command in the warning message?
  Because it was very simple to make the opencv portable with java and I want to realize if there is no problem then continue this method in future.</p>
  
  <p>I use JDK 9, Eclipse Oxygen.2, Fedora 27.</p>
  
  <p>In future, the application's target might be windows.</p>