title: Maven: Sharing resources between projects
body: <p>I am currently switching from ant to maven for a larger library consisting of a couple of projects. I am pretty new to Maven.</p>
  
  <p>Due to the fact, that multiple libraries require the same external files as input for testing, I decided to create an individual project containing the resources (Project1), as explained <a href="http://maven.apache.org/plugins/maven-remote-resources-plugin/examples/sharing-resources.html" rel="nofollow noreferrer">here</a>. <code>Project1</code> only contains the test resources, nothing else, except an class <code>project1.java</code> with an empty main method. The resource files are ASCII text and binary files with arbitrary file extensions. Now, I want to use these files in testing of other projects, e.g. Project2. I tried to illustrate my structure:</p>
  
  <pre><code>Root  
  |-Project1: Resources
  | |-src
  | | |-main
  |   |-test
  |     |-resources
  |       |-file1.txt
  |       |-file2.dat
  |       |-...
  |-Project2: Consumer
  | |-src
  | | |-main
  |   |-test
  |     |...
  |       |-test1.java (requires file1.txt)
  |       |-test2.java (requires file2.dat)
  |       |-...
  </code></pre>
  
  <p>I added <code>Project1</code> as a dependency in the POM of <code>Project2</code>. Both projects are built with Clean and Build from Netbeans 11, so I guess mvn clean, build &amp; install.</p>
  
  <p>I do test for the existance of the relevant file in <code>Project1</code> with <code>Project1.class.getClassLoader().getResource([FILE])</code> and all files seem to be at the correct location. However, if I use <code>Project1.class.getClassLoader().getResource([FILE])</code> from within <code>Project2</code>, e.g. <code>test1.java</code> the respective <code>FILE</code> is not found.</p>
  
  <pre><code>System.out.println("1:" + Project1.class.getClassLoader().getResource(""));
  System.out.println("2:" + Project1.class.getClassLoader().getResource("file1.txt"));
  </code></pre>
  
  <p>from within <code>test1.java</code> in <code>Project2</code> gives:</p>
  
  <pre><code>1: file:[PATHTOPROJECT]/Project2/target/test-classes/
  2: null
  </code></pre>
  
  <p>So I tried following the apporach in <a href="http://maven.apache.org/plugins/maven-remote-resources-plugin/examples/sharing-resources.html" rel="nofollow noreferrer">this description</a>. My problem with the explanation is, that I do not have a <code>plugin</code> to perform the <code>executions</code> for <code>maven-shared-archive-resources</code> as described in the consumer-part. Thus, I do not know where to put them. In the example the executions are carried out inside <code>&lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;</code> with <code>&lt;artifactId&gt;sql-maven-plugin&lt;/artifactId&gt;</code>.</p>
  
  <p>I also had a look at <a href="https://stackoverflow.com/questions/2247199/share-test-resources-between-maven-projects">this thread</a>, but I get an <code>Ant BuildException</code>. </p>
  
  <p>Could somebody be so kind and explain a maven novice, how I can share resources between different projects? Is there even another, simpler way?</p>
  
  <hr>
  
  <h2><code>POM.xml</code> of Project2</h2>
  
  <p>I tried to strip the <code>POM.xml</code> down to a MWE.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;!-- TOOL INFO --&gt;
      &lt;groupId&gt;org.test&lt;/groupId&gt;
      &lt;artifactId&gt;project2&lt;/artifactId&gt;
      &lt;version&gt;0.0.0.1&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;!-- PROPERTIES --&gt;
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;!-- System --&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;junit.jupiter.version&gt;5.3.1&lt;/junit.jupiter.version&gt;
          &lt;junit.platform.version&gt;1.0.0&lt;/junit.platform.version&gt;
          &lt;maven.compiler.source&gt;10&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;10&lt;/maven.compiler.target&gt;
          &lt;maven.plugin.compiler.version&gt;3.8.1&lt;/maven.plugin.compiler.version&gt;
          &lt;maven.plugin.enforcer.version&gt;3.0.0-M2&lt;/maven.plugin.enforcer.version&gt;
          &lt;maven.plugin.release.version&gt;2.5.3&lt;/maven.plugin.release.version&gt;
          &lt;maven.plugin.resources.remote.version&gt;1.6.0&lt;/maven.plugin.resources.remote.version&gt;
          &lt;maven.plugin.surefire.version&gt;3.0.0-M3&lt;/maven.plugin.surefire.version&gt;
          &lt;!-- Own --&gt;
          &lt;project1.version&gt;0.0.0.1&lt;/project1.version&gt;
      &lt;/properties&gt;
  
      &lt;!-- DEPENDENCIES --&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.test&lt;/groupId&gt;
              &lt;artifactId&gt;project1&lt;/artifactId&gt;
              &lt;version&gt;${project1.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
              &lt;artifactId&gt;junit-jupiter-api&lt;/artifactId&gt;
              &lt;version&gt;${junit.jupiter.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
              &lt;artifactId&gt;junit-jupiter-params&lt;/artifactId&gt;
              &lt;version&gt;${junit.jupiter.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.junit.jupiter&lt;/groupId&gt;
              &lt;artifactId&gt;junit-jupiter-engine&lt;/artifactId&gt;
              &lt;version&gt;${junit.jupiter.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;!-- BUILD --&gt;
      &lt;build&gt;
  
          &lt;!-- PLUGINS --&gt;
          &lt;plugins&gt;
  
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${maven.plugin.compiler.version}&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;${java.version}&lt;/source&gt;
                      &lt;target&gt;${java.version}&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-enforcer-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${maven.plugin.enforcer.version}&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;enforce&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
                  &lt;configuration&gt;
                      &lt;rules&gt;
                          &lt;requireJavaVersion&gt;
                              &lt;version&gt;${java.version}&lt;/version&gt;
                          &lt;/requireJavaVersion&gt;
                      &lt;/rules&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-release-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${maven.plugin.release.version}&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;localCheckout&gt;true&lt;/localCheckout&gt;
                      &lt;pushChanges&gt;false&lt;/pushChanges&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${maven.plugin.surefire.version}&lt;/version&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
  
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>