title: Maven : Using class from imported jar
body: <p>I'm quite new in Maven.<br>
  I'm trying to do following:<br>
  Suppose we have to projects A and B. Project B needs to use some classfrom_A from jar imported from A
  Here are definitions :
  POM.xml of project A : </p>
  
  <pre class="lang-xml prettyprint-override"><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;A_Group&lt;/groupId&gt;
    &lt;artifactId&gt;A_Artifact&lt;/artifactId&gt;
    &lt;version&gt;1.0&lt;/version&gt;
    &lt;packaging&gt;jar&lt;/packaging&gt;
    &lt;name&gt;A_Project&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;/project&gt; 
  </code></pre>
  
  <p>Here is POM.xml of project B (depends on A ) :</p>
  
  <pre class="lang-xml prettyprint-override"><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;B_Group&lt;/groupId&gt;
      &lt;artifactId&gt;B_Artifact&lt;/artifactId&gt;
      &lt;version&gt;1.0&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;name&gt;B_Project&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;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;A_Group&lt;/groupId&gt;
              &lt;artifactId&gt;A_Artifact&lt;/artifactId&gt;
              &lt;version&gt;1.0&lt;/version&gt;
              &lt;scope&gt;compile&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Here is code snippet from project B:   </p>
  
  <pre class="lang-java prettyprint-override"><code>import packageFromA.*;
  public class App {
      public static void main(String[] args) {
      classFromA ca = new ClassFromA; //from packageFromA 
      ca.someFunction();            
      }
  }
  </code></pre>
  
  <p>I run mvn install for A , then for B with no errors 
  But when trying to run code above from IntelliJ Idea, got error : 
  Error:(3, 18) java: package  packageFromA does not exist</p>
  
  <p>As I understand from maven docs : "compile dependencies are available in all classpaths, and they are packaged". But it seems that imported class still was not resolved . What was missing in the definitions ? Thanks in advance </p>
  
  <p>UPDATE: When running from IntelliJ the issue was resolved after re-import. But when I run from command line<br>
  <code>java projectB</code><br>
  Do I need explicitly set classpath of imported jars? If yes do I need point to i's location im local maven repository (.m2/repository) ? Thanks   </p>