how to run submodule file from maven command line
I am newbie in Maven, learning 101 from sonatype from http://books.sonatype.com/mvnex-book/reference/index.html
I am still puzzled on creating maven projects with submodules. I am using eclipse to create maven project and created module underneath it.
- Can maven project have source code or just POM file and source code is in modules?
I know I can run maven with following command, if there is no module and if all there exists is maven project
mvn exec:java -Dexec.mainClass="hello1"
In my case where I have maven project and submodules:
- Where should main method exist? in main project or module?
- What should be the command to execute that main method?
- What should be changes in pom.xml (and other configurations) if this main method has to call methods in other maven modules? Should I specify dependency on other jars or is there more to it?
I seem to get lost with these basic questions. I am using eclipse with m2e plugin and maven 3.X.
Re 1) I don't know whether it is impossible to have source code in the reactor/parent project, but it is not common. At least I have never seen a multi-module project that had code in the parent. Chapter 6 of the tutorial you reference also describes a POM-only parent and makes a point about the appropriate packaging type being "POM".
Re 2/3) Each module can have zero or many classes that implement a Main method. If one module requires another module to run, then yes, you declare that as a dependency in your module POM. To run a module you first have to run the install target of the reactor/parent. Then you can call the exec target in the module that you whish to run.
Having said that. As you are working with Eclipse, you need not do any of this if you have the m2e plugin installed. If you downloaded the J2EE version of Eclipse then it is already installed. The m2e plugin will dynamcally build the Eclipse buildpath/classpath of your modules based on the dependency information inside your POMs. You can simply right-click any class with a Main method and run it "as Java Application".