0

We have multiple JSP web applications that are all build using Maven, version 3.5.4. We need to create the same URL (may be /version.jsp or just /version) on all projects to return the version stored in pom.xml (or pom.properties). Additionally the response should be returned in HTML, XML or JSON depending on a parameter in the URL, but that will be another matter.

There are 20 plus projects and I don't want to copy and paste the same file and change the pom.properties file path over all projects. Maven places the pom.properties file on the /artifactId path. It could be a maintenance nightmare.

We use a parent pom.xml and one pom.xml on each project for the specifics. My idea is to configure something in the parent pom to place that version.jsp on all projects during the build. Is that possible? How? Would you do it differently?

Thank you

Dani Rodríguez
  • 72
  • 3
  • 13
  • @Andreas, thank you for the searching, I've also found these answers. They are useful but, from my point of view, they don't answer the question. The point of my question is how to get the version information with the **minimum duplicated code or files**. We have more than 20 projects to implement this solution. – Dani Rodríguez Nov 19 '19 at 06:29
  • **Minimum duplicated code or files:** Create a *shared* method, and call it in all the projects. If you have 20 projects, you should have a *shared* project where you put code that all of them needs. It's the only way to stay [**DRY**](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself). – Andreas Nov 19 '19 at 15:47
  • *Hint for your next question:* Include the research that you've already done, so we don't waste time repeating it, and you don't waste time clarifying your question. Exactly like it says in the beginning of the Help Center article [**How do I ask a good question?**](https://stackoverflow.com/help/how-to-ask) *"Keep track of what you find. Even if you don't find a useful answer elsewhere on the site, **including links to related questions that haven't helped** can help others in understanding how your question is different from the rest."* – Andreas Nov 19 '19 at 15:50

1 Answers1

0

Finally, we end up by creating a servlet in a referenced project (i.e.: common.jar) and referencing that servlet in web.xml of the web application. The group and artifact ID of maven are specified as init parameters of the servlet in the web.xml.

I don't know if it's the best option, but at least it works and the maintenance is not so bad. The functionality related to the version is centralized and the only thing that is duplicated in all projects is the reference of the servlet.

Dani Rodríguez
  • 72
  • 3
  • 13