title: How do I use log4j with Maven and executable jar file?
body: <p>I'm trying to get log4j working in a simple application but I'm getting the message: </p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
  </code></pre>
  
  <p>I execute the application with the command:  </p>
  
  <pre><code>java -jar lunchtracker-1.0-SNAPSHOT.jar
  </code></pre>
  
  <p>The log4j.properties file is in src/main/resources.  Here is my pom.xml:</p>
  
  <pre><code>&lt;project &lt;snip -- was messing up formatting&gt;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;net.uofitorn&lt;/groupId&gt;
      &lt;artifactId&gt;lunchtracker&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;lunchtracker&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&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;archive&gt;
                          &lt;manifest&gt;
                              &lt;addClasspath&gt;true&lt;/addClasspath&gt;
                              &lt;classpathPrefix&gt;lib/&lt;/classpathPrefix&gt;
                              &lt;mainClass&gt;net.uofitorn.LunchTrackerServer&lt;/mainClass&gt;
                          &lt;/manifest&gt;
                      &lt;/archive&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;1.2.16&lt;/version&gt;
              &lt;scope&gt;compile&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Here is my java code:</p>
  
  <pre><code>import org.apache.log4j.Logger;
  &lt;snip&gt;
  Logger logger = Logger.getLogger(LunchTrackerServer.class.getName());
  logger.debug("Server started");
  </code></pre>
  
  <p>I think the problem is the log4j jar is not being included in my jar file.  When I unzip the jar I don't see it.  How do I get maven to include the log4j dependency in my jar?</p>