I have a maven web-service project consisting of two different service classes testClass1 and testClass2 . I want to have two different WAR files for both classes of same project. Presently I am generating single WAR file for both services .
How can I generate two different WAR file for same project ? Thanks In Advance.
As per doc says, what you try to achieve is a bad pratice :
Producing Multiple Unique JARs from a Single Source Directory
As many people that complain about not being able to spread out their sources into multiple source directories seem to complain about not wanting to spread anything out, producing several unique artifacts from a single directory using includes and excludes.
Why isn't this recommended?
This practice can be confusing and risky.
You may end up building two JARs that include the same classes - this indicates that the common functionality should have been abstracted into a separate dependency. You may end up introducing a dependency between the two JARs that you didn't realise, and often a circular dependency. This indicates that the classes are in the wrong JAR, or perhaps that everything should just be a single JAR.
You should consider splitting you project into two differents ones, having each one a pom, and so each one generating an artifact, here a war.
You may achieve that by using either two simple projects :
service1-simple-webproject
|-- src
`-- pom.xml
service2-simple-webproject
|-- src
`-- pom.xml
This is quite simple, but you may not be able tho share easily properties / dependencies / relations between them.
Just split your own code into separates directory, and try to make it work as two independant projects.
If you think that there is some code to share between them (utilities, configuration, ...), see next section about multi module.
Or you can use an appopriate multi-module hierarchy :
parent-multimodule-project
|-- service1-simple-webmodule
| |-- src/
| `-- pom.xml
|-- service2-simple-webmodule
| |-- src
| `-- pom.xml
`-- pom.xml
This will allow you to have relations between projects, share configuration at a higher level, ... Ta ke a look to this documentation :
I will probably lead you to create a third project, probably named core, or util, that would produce a jar which will contains common classes to both web project.
This is really the best way !
I would only give you some information, because I'm even sure it could work in this case.
Maven Assembly Plugin allow you to generate different format of package (zip, jar, war, other, ...) based on xml description files. Here documentation : http://maven.apache.org/plugins/maven-assembly-plugin/
Once again, I strongly advise you to NOT use this kind of workaround.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With