title: How do I package and run a simple command-line application with dependencies using maven?
body: <p>I am brand new to both java and to maven, so this is likely very simple.</p>
  
  <p>If I follow the maven2 <code>hello world</code> instructions here:</p>
  
  <p><a href="http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html" rel="noreferrer">http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html</a></p>
  
  <p>everything works OK.  If I then alter <code>pom.xml</code> to bring in a dependency from a remote repository, the files for this dependency get stored in <code>~/.m2/repository/new-dependency/</code>.</p>
  
  <p>Using the syntax in the <code>hello world</code> instructions to run the application requires that I add the absolute path to the dependency to my classpath (either by setting the environment variable or via the command line switch):</p>
  
  <pre><code>java -cp target/my-app-1.0-SNAPSHOT.jar:/.../.m2/.../new-dependency.jar com.mycompany.app.App
  </code></pre>
  
  <p>This will obviously get unwieldy quickly :)</p>
  
  <p>I suspect that this is not the usual way of running a java program and that I just need to read more about .jar files, but while I am doing so I would appreciate any tips on how to do this properly.</p>
  
  <p>I am not using an IDE, btw.  vim from the command line.</p>
  
  <p>Thanks!</p>
  
  <p>Mike.</p>