简体   繁体   中英

how to create 2 separate war files

I'm working on this huge java maven project that has several components to it. This project will be delivered to several clients the exact same way except for 1 small part for 1 of the clients.

This client provided me a single jar file that I should use when logging information.

Now here's my question - how do I create two war files - 1 with the jar file that the customer provided me, and 1 without.

I started looking into feature toggling - but feature toggling would require me to deliver the proprietary jar file to other customers because the code won't compile since there is still a dependency and I would only have 1 war file.

Look at using maven profiles to compile and package different dependencies with your project artifact.

This is a similar question to this one.

I don't quite get the problem you have: If your application code needs that "special logging" to work, simply pulling that out is not going to work, as you said, your code will need the "special logging" library to run.

Have you done something to abstract out the usage of the "special logging" so that you will have alternatives for other customers?

One way to proper arrange your project is making the two WAR as different projects, and define different dependencies in them, so that it looks like:

+ foo
  + foo-main              // project contains main shared code
  + foo-war-special-log   // war project that have dependencies to special logging
  + foo-war-normal-log    // war project that depends on alternative logging

There are also other ways like, you can also make use of assembly plugin or war plugin to control dependencies included in wars, and build both war in same project giving different classifiers to distinguish them. However I think having separate project is much easier to handle.

Thank you guys for the responses that you provided above. Although, you provided 2 good solutions, they wouldn't work for what I was trying to do.

One of my co-workers helped me solve this issue by using maven overlays.

The basic gist is that I have a project called foo. I copied and pasted that exact project next to it and called it foo_with_logging. In my pom file for the new project, I made a dependency on project foo.

Please let me know if you have any questions.

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