2

We are trying to migrate our existing Spring MVC applications to Spring Boot application. Our existing applications are using 3.2.9, so tons of XML configurations. All the beans are defined in the XML files. What we have done is first we have upgraded our existing applications to Spring 4.2.5 version since Spring Boot will work only with Spring 4 versions.

Our requirement is to have both FAT JARs and WAR files from the build. Most of our existing customers would prefer Application Server deployment, so we have to create WAR file for them. Also for our internal testing and new deployments, we are planning to use FAT JARs.

How can we achieve them in the Maven file, we are able to provide separately as below. Is there any maven plug-in to generate both in single build?

<packaging>jar</packaging>

or

<packaging>war</packaging>

We are publishing our artifacts into Nexus repository. So, we want to have the separate repository location for JAR files and WAR files. Can we do that using the single pom.xml file?

Also another question, we have all the XML configurations under WEB-INF folder. When we are moving to the Spring Boot application, it has to be under the resources folder. How can we handle them easily. When we build FAT jars, the resources are not looked under WEB-INF because it simply ignores the webapp project.

I am looking forward for some guidance to complete the migration. Infact, we have already done that changes and it is working fine, but we are confused on this WAR / JAR generations.

Update: I have got another question in mind, if we are converting our existing applications to spring boot, do we still have to maintain WEB-INF folder in the web-app or can move everything to the resources folder?. While building the WAR file, whether spring boot takes care of moving the resources to WEB-INF? How spring boot would manage to create the WAR file if you are putting all the resources under the resources folder.

Krishna
  • 7,154
  • 16
  • 68
  • 80

2 Answers2

3

Building WAR and FAT JAR is very easy with Gradle.

With Maven, I would try multi module setup, where one sub-module will build fat JAR and second will build WAR file.

Application logic can be as third sub-module and thus being standalone JAR with Spring configuration and beans. This application logic JAR would be as dependency for fat JAR and WAR module. WAR specific configuration can be placed in Maven WAR sub-module.

I didn't have such requirement before, so don't know what challenges may occur. For sure I wouldn't try to integrate maven-assembly-plugin or other packaging plugins with spring-boot-maven-plugin.

Concerning location of config files, just place them into src/main/resources or it's sub-folders according Spring Boot conventions. Spring Boot is opinionated framework and will be most friendly to you if you don't try to resist defaults.

Software Engineer
  • 15,457
  • 7
  • 74
  • 102
luboskrnac
  • 23,973
  • 10
  • 81
  • 92
  • I have another question, if we are converting to spring boot, do we still have to maintain WEB-INF folder and we can move everything to the resources folder? – Krishna Apr 05 '16 at 09:45
  • 1
    I think you should move everything into resources folder. – luboskrnac Apr 05 '16 at 09:50
  • 1
    I have a lot of professional experience of gradle on big complex projects at major blue-chip companies, and if I were in your shoes I would avoid it like the plague -- it's horrible in every possible respect and is very likely to mess up your whole project. Stick with maven -- this one hassle will be nothing compared to the problems gradle will introduce. – Software Engineer Apr 05 '16 at 10:44
  • @EngineerDollery I had a much better opinion on Gradle before i saw your comment :) is that so horrible to work with Gradle? – Krishna Apr 05 '16 at 10:54
  • It's very popular, but mostly with hipsters and inexperienced engineers who don't know what 'good' looks like. It's broken by design. Gradle is an upgraded version of Ant, with all the problems that tool had. Plus, you have to learn groovy -- an unpopular language at best. While maven has its problems -- xml shouldn't be written by humans -- at least its a Convention over Configuration based tool, rather than a big scripting system. Some things initially seem easier in gradle, like the problem you have here, but I've never seen anyone produce anything good with it, across 20 major projects. – Software Engineer Apr 05 '16 at 11:36
2

Maven does not handle this gracefully, but its far from difficult to solve. You can do this with 3 pom files. One parent pom that contains the majority of the configuration, and one each for the packaging portion of the work. This would neatly separate the concerns of the two different assembly patterns too.

To clarify -- I'm not recommending a multi-module configuration here, just multiple poms with names like war-pom.xml and fat-jar-pom.xml, along with parent-pom.xml.

Software Engineer
  • 15,457
  • 7
  • 74
  • 102
  • Yes. I have the same thing in my mind. It is better I would create multiple POM files. – Krishna Apr 05 '16 at 10:53
  • How is this different from what I suggested? – luboskrnac Apr 05 '16 at 11:10
  • @luboskrnac: I'm not recommending a multi-module config, just multiple poms. I don't think you should have a module just for artefact creation. I think you should have a war-pom.xml and a fat-jar-pom.xml along with a parent-pom.xml, all for the one module. I'll add this to the answer to clarify. – Software Engineer Apr 05 '16 at 11:26
  • OK, you should also mention, that if it's separate POM, it's treated as separate project, should be also versioned separately and hosted in separate Git repository, deployed in separate builds into artifact repository. From my point of view, too much hassle for no reason. – luboskrnac Apr 05 '16 at 11:36
  • This is true, but only if the project is going through a standard CI/CD process (which it should be) -- because CI/CD is typically configured to run a single build and produce a single artefact and push that through an automated testing framework. That's also true of your multi-module solution though and is about the same amount of hassle. If it's for some other reason can you clarify? I just don't like the idea of creating a module that only pumps out an artefact and has no content of its own other than the pom. – Software Engineer Apr 05 '16 at 11:50
  • @luboskrnac I am also happy with your answer. Multi module also a good solution – Krishna Apr 06 '16 at 05:10