title: Execute a separate Java process in the classpath of a module
body: <p>For testing purposes, I'm trying to run a Java application built from multiple Maven modules in a single project using a main class from the command line. I'd like to be able to specify JVM arguments, Java System Properties as well as command line arguments for the main class, but these are all secondary goals.</p>
  
  <p>I've set up a simple project with the following structure:</p>
  
  <pre><code>./module1/pom.xml
  ./module1/src/main/java/com/example/ClassInModule1.java
  ./module2/module2.iml
  ./module2/pom.xml
  ./module2/src/main/java/com/example/ClassInModule2.java
  ./pom.xml
  </code></pre>
  
  <p><code>module2</code> depends on <code>module1</code> via the following declaration in <code>module2/pom.xml</code>:</p>
  
  <pre><code>&lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.example&lt;/groupId&gt;
          &lt;artifactId&gt;module1&lt;/artifactId&gt;
          &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>I want to use class <code>com.exmaple.ClassInModule2</code> as the main class. To do this I tried using the <code>exec:exec</code> goal of the plugin <code>exec-maven-plugin</code>:</p>
  
  <pre><code>mvn -pl module2 -Dexec.executable=java -Dexec.args='com.example.ClassInModule2' exec:exec
  </code></pre>
  
  <p>But this leads to the following error:</p>
  
  <pre><code>[INFO] Scanning for projects...
  [INFO]                                                                         
  [INFO] ------------------------------------------------------------------------
  [INFO] Building module2 1.0.0-SNAPSHOT
  [INFO] ------------------------------------------------------------------------
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 0.450s
  [INFO] Finished at: Thu Sep 11 13:31:16 CEST 2014
  [INFO] Final Memory: 7M/245M
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal on project module2: Could not resolve dependencies for project com.example:module2:jar:1.0.0-SNAPSHOT: Could not find artifact com.example:module1:jar:1.0.0-SNAPSHOT -&gt; [Help 1]
  </code></pre>
  
  <p>Which is strange because <code>module1</code> is recorded in <code>./pom.xml</code>. I tried adding <code>-am</code> to the command line:</p>
  
  <pre><code>mvn -am -pl module2 -Dexec.executable=java -Dexec.args='com.example.ClassInModule2' exec:exec
  </code></pre>
  
  <p>But this leads to a different error:</p>
  
  <pre><code>[INFO] Scanning for projects...
  [INFO] ------------------------------------------------------------------------
  [INFO] Reactor Build Order:
  [INFO] 
  [INFO] project
  [INFO] module1
  [INFO] module2
  [INFO]                                                                         
  [INFO] ------------------------------------------------------------------------
  [INFO] Building project 1.0.0-SNAPSHOT
  [INFO] ------------------------------------------------------------------------
  [INFO] 
  [INFO] --- exec-maven-plugin:1.3.2:exec (default-cli) @ project ---
  Error: Could not find or load main class com.example.ClassInModule2
  </code></pre>
  
  <p>It seems that the plugin is trying to run the command in parent project, where the main class can't be found.</p>
  
  <p>What am I doing wrong? How can I use the <code>exec:exec</code> goal in a multi-module project?</p>