简体   繁体   中英

Maven: project setup

I am starting a new project as well as starting with Maven. I am not sure my project-structure with Maven is decent and so I would like to ask. I describe the project with a little example.

The projects name should be MyPrj.

It consists of 3 parts (server, client, lib).

Server and client are programs (main) and lib does include helper-classes both will use (eg for logging).

I designed 3 maven-projects - 1 per part.

MyPrj/
  client/
     pom.xml, src, target, ...
  server/
     pom.xml, src, target, ...
  lib/
     pom.xml, src, target

The parts java package-names are

MyPrj.client
MyPrj.server
MyPrj.lib

The maven addressing is

groupId: MyPrj, artifactId: client, version: 0.1
groupId: MyPrj, artifactId: server, version: 0.1
groupId: MyPrj, artifactId: lib, version: 0.1

In them POM of client and server is a dependency to lib.

<dependency>
  <groupId>MyPrj</groupId>
  <artifactId>lib</artifactId>
  <version>0.1</version>
</dependency>

Is that setup ok or not typical for a maven project?

Your Maven project looks good but you missed one thing : the parent .

Your MyPrj project should have its own pom.xml .

MyPrj/
  pom.xml
  client/
     pom.xml, src, target, ...
  server/
     pom.xml, src, target, ...
  lib/
     pom.xml, src, target

In the pom.xml of MyPrj , you can declare the submodules of your Maven project as following :

<project>
  ...

  <modules>
    <module>client</module>
    <module>server</module>
    <module>lib</module>
  </modules>
</project>

The parent of multi-module Maven project has a lot of interesting features (dependencies management, repositories, SCM management, ...).

I suggest you to take a look to the following documentation :

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM