Ka Pr
Ka Pr

Reputation: 85

What is the best way to structure maven projects to make a client jar?

New to maven here...coming from the ant world

I need to create a client jar with a few files that will give my client the ability to write to my Db and make rest calls to my services. These are mainly classes that wrap a Rest connection and db client.

Is it possible to produce this artifact as a side effect of my main maven project ? Eg: main project produces a bundle when I run mvn package, but I'd like to produce the client jar by providing some other parameters....

Upvotes: 1

Views: 208

Answers (2)

RITZ XAVI
RITZ XAVI

Reputation: 3789

What you need here is a multi-module maven project.

The structure goes like this:

-- Parent Module
----- Child 1 Module
----- Child 2 module

Here you can have all your code/files of your main app in child 1 module and put all the code/files for the client in the child 2 module.

The parent module is just an aggregator which produces an artifact of type pom. Whereas each of your child modules will produce individual jars. You can then you the second jar in your client.

For a detailed understanding how multi-module project works, check this link.

Upvotes: 1

J Fabian Meier
J Fabian Meier

Reputation: 35795

The standard Maven way is "one project, one jar". This means that the cleanest way to achieve your goal is to set up a multi-module project where you have one module for your "normal" jar and one for your "client" jar. But there are other possibilities:

  1. If you are talking about an ejb, you can use the maven-ejb-plugin and create a client artifact. Unfortunately, both artifacts then share the same pom (and, therefore, the same dependencies).

  2. You can use the maven-assembly-plugin to assemble a set of files and deploy them as side artifact (same problem as in (1)).

  3. You can use the maven-install-plugin and maven-deploy-plugin to install/deploy entirely different artifacts along with your main artifact. These artifacts need to be created before, e.g. by a custom maven plugin.

Upvotes: 0

Related Questions