title: ant to maven conversion: correct approach?
body: <p>I am tasked with converting a java project which is created with <code>ant</code> to <code>maven</code>.</p>
  <p>This is how the project is set up.</p>
  <ol>
  <li><p>All the sources are stored in <code>src</code> directory.</p>
  </li>
  <li><p><code>ant</code>'s compiling target is to compile the entire <code>src</code> directory.</p>
  </li>
  <li><p><code>ant</code>'s packaging target has several sub-targets.</p>
  <p>Each target has different jars which has <code>include</code> or <code>exclude</code> directories.</p>
  </li>
  </ol>
  <p>This is the approach that I took.</p>
  <ol>
  <li><p>Find out all dependencies. Store them in <code>DependencyManagement</code> section of <code>parent pom</code></p>
  </li>
  <li><p>Create a module and copy entire <code>src</code> directory.</p>
  </li>
  <li><p>compiled it.</p>
  </li>
  <li><p>Tried to create separate modules for different <code>jar</code> files.</p>
  </li>
  </ol>
  <p><strong>Problem</strong>: the files are in-separable. Most of the files are depending on other files. I tried separating them. It results in creating cyclic dependencies. Hence, this step failed.</p>
  <ol start="5">
  <li>Use different profiles and <code>maven-jar-plugin</code> to <code>include</code> or <code>exclude</code> packages.</li>
  </ol>
  <p><strong>Question 1</strong> when I tried this <code>mvn install -P profile1,profile2</code>, <code>target</code> has only <code>jar</code> file for <code>profile2</code>. They both have <code>maven-jar-plugin</code> and each has different <code>finalName</code>.</p>
  <pre><code>    &lt;profile&gt;
          &lt;id&gt;profile1&lt;/id&gt;
          &lt;build&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
                      &lt;configuration&gt;
                          &lt;includes&gt;
                              &lt;include&gt;**/src/.../profile1/**&lt;/include&gt;
                          &lt;finalName&gt;profile1-lib&lt;/finalName&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/build&gt;
      &lt;/profile&gt;
  </code></pre>
  <p>Is there a different command or am I doing something wrong?</p>
  <p><strong>Question 2</strong> one of the lib has several <code>image</code> files in it.</p>
  <p>The above approach does not copy the <code>image</code> files in the result <code>jar</code>.</p>
  <p>I understand <code>maven</code> wants all resources in <code>resources</code> directory. I will move the images, but for now I am trying to include them in the <code>jar</code>.</p>
  <p>I added <code>maven-resources-plugin</code>.</p>
  <pre><code>                &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
                      &lt;version&gt;3.0.2&lt;/version&gt;
                      &lt;executions&gt;
                          &lt;execution&gt;
                              &lt;phase&gt;validate&lt;/phase&gt;
                              &lt;goals&gt;
                                  &lt;goal&gt;copy-resources&lt;/goal&gt;
                              &lt;/goals&gt;
                              &lt;configuration&gt;
                                  &lt;outputDirectory&gt;${basedir}/target/classes&lt;/outputDirectory&gt;
                                      &lt;resource&gt;
                                          &lt;directory&gt;src/main/java/jpl/mipl/mdms/FileService/komodo/ui/savannah/subscription/util/resources&lt;/directory&gt;
                                      &lt;/resource&gt;
                                  &lt;/resources&gt;
                              &lt;/configuration&gt;
                          &lt;/execution&gt;
                      &lt;/executions&gt;
                  &lt;/plugin&gt;
  </code></pre>
  <p>When I run <code>mvn install -P profile1</code>, I can see the logs saying <code>Copying # resources</code>.</p>
  <p>I can also see them being copied to target/classes. the path that I gave to the plug-in. But they are all copied to that directory.</p>
  <p>I want to retain the structure, and the result <code>jar</code> still doesn't have it.</p>
  <p><strong>Answer:</strong> I have to move them to <code>resources</code> directory. <code>maven</code> is strict.
  Anything that I should be doing differently?</p>
  <p><strong>Extra Question</strong> Am I using the correct plug-ins? Or is there more efficient plug-ins that I should be using?</p>
  <p>Thank you.</p>