I'm learning Maven. I was tinkering with it and was struck at this issue,
I've two maven projects Project_1 and Project_2
Project_1 Sample code :
package com.sample;
public class App
{
public void hello(){
System.out.println("Hello from New Project1");
}
public static void main( String[] args )
{
//Empty
}
}
I build project_1 and added the JAR file as dependency to project 2.
Project_2 Sample code :
package com.newsample;
import com.sample.App;
public class Appn
{
public static void main( String[] args )
{
App obj=new App();
obj.hello();
}
}
Project_2 POM.xml dependency :
<dependency>
<groupId>com.sample</groupId>
<artifactId>project1</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
However, When I try to run the package from the JAR file, it is throwing below error :
Exception in thread "main" java.lang.NoClassDefFoundError: com/sample/App
I've checked the project_2 JAR file but App.class was not added to it. My question seems to be naive, but shouldn't the class be added since it is a dependency for project_2. Is there any other way to bundle this using maven?