title: Maven project - load file from outside of resources folder (project root)
body: <p>I am creating a contacts application using Maven in Netbeans. For the operation of the program I want users to add and store images (contact avatars) in a folder /avatars and access them on a listener event. I can access images from within the ProjectRoot/src/main/resources/images directory, but cannot access ProjectRoot/avatars. <em>Note: I do not want to store avatars in the resources directory because these will be user-added during the programs operation.</em></p>
  
  <p>I have tried using getClass().getResource(avatarPath); as suggested in similar questions, but it has not worked. I have also tried adding the "avatars" directory to the POM as its own resource directory, but that has not worked either. </p>
  
  <p><strong>How can I access files/folders in the root directory of my project when using Maven?</strong></p>
  
  <pre><code>listviewContacts.getSelectionModel().selectedItemProperty().addListener(new ChangeListener&lt;Contact&gt;() {
          @Override
          public void changed(ObservableValue&lt;? extends Contact&gt; observable, Contact oldValue, Contact newValue) {
              String avatar = newValue.getAvatar();
              String avatarPath = null;
              if (avatar.isEmpty()) {
                  avatarPath = "/images/" + DEFAULT_AVATAR; // loads from ProjectRoot/src/main/resources/images
              } else {
                  avatarPath = "/avatars/" + avatar; // won't load from ProjectRoot/avatars
              }
              try {
                  imageviewContact.setImage(new Image(avatarPath));
              } catch (IllegalArgumentException ex) {
                  System.err.println("Could not locate " + avatarPath);
              }
          }
  
      });
  </code></pre>