title: How to generate a resource to be included in Jar file with maven?
body: <p>During my build I need to some files to be generated by an external tool. For my minimal compilable example I reduced my "external tool" to the following script:</p>
  
  <pre class="lang-bash prettyprint-override"><code>mkdir -p target/generated-resources
  echo "hello world" &gt; target/generated-resources/myResource.txt
  </code></pre>
  
  <p>Now I want to execute my external tool during build and the generated resource should be included in the war file. I could not find any documention on how that should be done, so it was just a guess that I need to write my generated resource to <code>target/generated-resources</code>. So maybe that is a problem?</p>
  
  <p>I created a pom.xml file with the following build configuration:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
              &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;1.2.1&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;phase&gt;generate-resources&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;exec&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
              &lt;configuration&gt;
                  &lt;executable&gt;./createResource.sh&lt;/executable&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p>If I run <code>mvn package</code> my createResource.sh script gets executed successfully and the myResource.txt file is created. However the myResource.txt file is not included in the resulting .jar file.</p>
  
  <p>I noticed that it works if I add</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;resources&gt;
    &lt;resource&gt;
      &lt;directory&gt;target/generated-resources&lt;/directory&gt;
    &lt;/resource&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>to my build config, but I fear that this may cause problems if other plugins which may use this directory differently (Do they? I could not really find anything about the conventions of the <code>target</code> directory).</p>
  
  <p>Additionally I'd prefer a solution that works with the usual maven conventions (if a convention for this case exists).</p>
  
  <p>How do I correctly generate a resource to be included in the jar file during build using maven?</p>