title: Error: Could not find or load main class ... - Maven project out of Eclipse
body: <p>I created a Maven project with Eclipse and I am able to run the <code>App.java</code> in Eclipse. But now I want to run it out of Eclipse with this command:</p>
  
  <pre><code>..\workspace\subscribe\target\classes&gt; java com.mqtt.subscribe.App 
  </code></pre>
  
  <p><strong>EDIT:</strong> with executable <code>jar</code>:</p>
  
  <pre><code>..\workspace\subscribe&gt;java -jar target\subscribe-0.0.1-SNAPSHOT.jar
  </code></pre>
  
  <p>and get this error:</p>
  
  <blockquote>
    <p>Error: Could not find or load main class com.mqtt.subscribe.App</p>
  </blockquote>
  
  <p>What I am doing wrong? I don't understand it.</p>
  
  <p>I also try to rebuild the project with <code>mvn package</code> and <code>mvn clean install</code> in <code>cmd</code>. I get always the same error. </p>
  
  <p><strong>EDIT:</strong> I also tried to make an executable <code>jar</code> file, Still the same error.</p>
  
  <p>Thank you for your help.</p>
  
  <p>System variables set like:</p>
  
  <pre><code>JAVA_HOME = C:\Program Files\Java\jdk1.8.0_121
  Path = C:\Program Files\Java\jdk1.8.0_121\bin;C:\Program Files\Maven\apache-maven-3.3.9\bin
  </code></pre>
  
  <h3><code>pom.xml</code></h3>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
    &lt;groupId&gt;com.mqtt&lt;/groupId&gt;
    &lt;artifactId&gt;subscribe&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
  
    &lt;name&gt;subscribe&lt;/name&gt;
    &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
    &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
    &lt;/properties&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;version&gt;3.0.0&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;archive&gt;
                      &lt;manifest&gt;
                          &lt;addClasspath&gt;true&lt;/addClasspath&gt;
                          &lt;mainClass&gt;com.mqtt.subscribe.App&lt;/mainClass&gt;
                      &lt;/manifest&gt;
                  &lt;/archive&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
              &lt;configuration&gt;
                  &lt;descriptorRefs&gt;
                      &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
                  &lt;/descriptorRefs&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  
    &lt;repositories&gt;
      &lt;repository&gt;
          &lt;id&gt;Eclipse Paho Repo&lt;/id&gt;
          &lt;url&gt;https://repo.eclipse.org/content/repositories/paho-releases/&lt;/url&gt;
      &lt;/repository&gt;
    &lt;/repositories&gt;
  
    &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.eclipse.paho&lt;/groupId&gt;
          &lt;artifactId&gt;org.eclipse.paho.client.mqttv3&lt;/artifactId&gt;
          &lt;version&gt;1.0.2&lt;/version&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <h3><code>App.java</code></h3>
  
  <pre><code>package com.mqtt.subscribe;
  
  import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
  import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
  import org.eclipse.paho.client.mqttv3.MqttCallback;
  import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
  import org.eclipse.paho.client.mqttv3.MqttException;
  import org.eclipse.paho.client.mqttv3.MqttMessage;
  import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
  
  public class App implements MqttCallback {
  
      public static void main(String[] args) {
          String topic = "TEST";
          int qos = 2;
          String broker = "tcp://broker.hivemq.com:1883";
          String clientId = "Test";
          MemoryPersistence persistence = new MemoryPersistence();
  
          try {
  
              MqttAsyncClient sampleClient = new MqttAsyncClient(broker, clientId, persistence);
              MqttConnectOptions connOpts = new MqttConnectOptions();
              connOpts.setCleanSession(true);
              sampleClient.setCallback(new App());
              System.out.println("Connecting to broker: " + broker);
              sampleClient.connect(connOpts);
              System.out.println("Connected");
              Thread.sleep(500);
              sampleClient.subscribe(topic, qos);
              System.out.println("Subscribed");
          } catch (Exception me) {
              if (me instanceof MqttException) {
                  System.out.println("reason " + ((MqttException) me).getReasonCode());
              }
              System.out.println("msg " + me.getMessage());
              System.out.println("loc " + me.getLocalizedMessage());
              System.out.println("cause " + me.getCause());
              System.out.println("excep " + me);
              me.printStackTrace();
          }
      }
  
      public void connectionLost(Throwable arg0) {
          System.err.println("connection lost");
  
      }
  
      public void deliveryComplete(IMqttDeliveryToken arg0) {
          System.err.println("delivery complete");
      }
  
      public void messageArrived(String topic, MqttMessage message) throws Exception {
          System.out.println("topic: " + topic);
          System.out.println("message: " + new String(message.getPayload()));
      }  
  }
  </code></pre>
  
  <h3><code>CMD</code>:</h3>
  
  <pre><code>C:\Users\test\workspace\subscribe&gt;mvn clean install
  [INFO] Scanning for projects...
  [INFO]
  [INFO] ------------------------------------------------------------------------
  [INFO] Building subscribe 0.0.1-SNAPSHOT
  [INFO] ------------------------------------------------------------------------
  [INFO]
  [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ subscribe ---
  [INFO] Deleting C:\Users\test\workspace\subscribe\target
  [INFO]
  [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ subscribe
  ---
  [INFO] Using 'UTF-8' encoding to copy filtered resources.
  [INFO] skip non existing resourceDirectory C:\Users\test\workspace\subscribe
  \src\main\resources
  [INFO]
  [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ subscribe ---
  [INFO] Changes detected - recompiling the module!
  [INFO] Compiling 1 source file to C:\Users\test\workspace\subscribe\target\c
  lasses
  [INFO]
  [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ su
  bscribe ---
  [INFO] Using 'UTF-8' encoding to copy filtered resources.
  [INFO] skip non existing resourceDirectory C:\Users\test\workspace\subscribe
  \src\test\resources
  [INFO]
  [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ subscri
  be ---
  [INFO] Nothing to compile - all classes are up to date
  [INFO]
  [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ subscribe ---
  [INFO] No tests to run.
  [INFO]
  [INFO] --- maven-jar-plugin:3.0.0:jar (default-jar) @ subscribe ---
  [INFO] Building jar: C:\Users\test\workspace\subscribe\target\subscribe-0.0.
  1-SNAPSHOT.jar
  [INFO]
  [INFO] --- maven-install-plugin:2.4:install (default-install) @ subscribe ---
  [INFO] Installing C:\Users\test\workspace\subscribe\target\subscribe-0.0.1-S
  NAPSHOT.jar to C:\Users\test\.m2\repository\com\mqtt\subscribe\0.0.1-SNAPSHO
  T\subscribe-0.0.1-SNAPSHOT.jar
  [INFO] Installing C:\Users\test\workspace\subscribe\pom.xml to C:\Users\test\.m2\repository\com\mqtt\subscribe\0.0.1-SNAPSHOT\subscribe-0.0.1-SNAPSHOT.p
  om
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD SUCCESS
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 2.049 s
  [INFO] Finished at: 2017-02-26T17:50:53+01:00
  [INFO] Final Memory: 15M/212M
  [INFO] ------------------------------------------------------------------------
  
  C:\Users\test\workspace\subscribe&gt;java -jar target\subscribe-0.0.1-SNAPSHOT.
  jar
  Error: Could not find or load main class com.mqtt.subscribe.App
  </code></pre>