0

I created a parent Maven project in Eclipse. Created a maven model under the parent project using below command

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=RELEASE -DgroupId=Saurabh -DartifactId=CucumberProject -Dversion=1.1 -DinteractiveMode=false

Refer below folder structure:

enter image description here

When I try to run App.java under CucumberProject module, I am getting below error: enter image description here

I think the issue is due to absence of Source folder under CucumberProject module (if this is the case then I need to create it programmatically) because the aim is to create the entire structure using command/programmatically and I don't want any manual intervention.

Please suggest what is the actual issue. Thank You.

  • Can you detail what you are doing when you are trying to run App.java - also can you include the contents of App.java please. – 0xadecimal Sep 26 '19 at 09:54
  • @0xadecimal It just prints a "hello world" string. It's the default java class created when a project is created. – Michael Corleone Sep 26 '19 at 10:15
  • what exactly are you trying to create? Because by the looks of it this is a project structure to create a new maven archetype, not a Java application you can run – Gimby Sep 26 '19 at 11:14
  • @Gimby I need to create source folder for module "CucumberProject" (CucumberProject/src/main/java) in parent, but need to do it programmatically/command. Basically I need to create multi modules under 1 parent project and modules must be executable i.e classed created under modules must be executable. – Michael Corleone Sep 26 '19 at 17:22
  • Eclipse itself has only it's own project handling and does not know anything about Maven. It is the built-in plugin m2eclipse which takes care of translating information that is in the pom files and syncing that with the Eclipse project structures. There is no real "programmatic" thing to do, you need to make sure that m2eclipse can do it's work properly. That starts with having proper pom structures. If you have a proper parent pom with modules in it then m2eclipse should be able to import the modules as a separate Eclipse project like basin already explained. – Gimby Sep 27 '19 at 11:21

1 Answers1

0

You have imported a wrong maven project. Close the parent, import the child project and it's going to work. Actually, Eclipse does not support nested projects. For better compatibility, put the parent project in a folder near the child project and set the <relativePath>../parent/pom.xml</relativePath> inside <parent>. Similarly, use <module>../childfolder</module> in the parent pom.

basin
  • 3,949
  • 2
  • 27
  • 63
  • I need to create source folder for module "CucumberProject" (CucumberProject/src/main/java) in parent, but need to do it programmatically/command. Basically I need to create multi modules under 1 parent project and modules must be executable i.e classed created under modules must be executable. – Michael Corleone Sep 26 '19 at 17:18
  • @MichaelCorleone you still have to import the child project in Eclipse – basin Sep 26 '19 at 17:54