I am using:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
</plugin>
with Spring Boot application I am adding BuildNumber into META-INF\MANIFEST.MF in WAR file.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
When I start this application like:
java -jar MyApp.war
everything is fine.
When I start it in tomcat (apache-tomcat-8.0.33 ) as ROOT application - extracted resources into ROOT directory (no WAR file used) application is not able to find my BuildNumber.
method which is looking for BuildNumber is here:
@PostConstruct
private void init() {
try {
Enumeration<URL> resources = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
LOGGER.debug("Looking into URL: {} for BuildNumnber", url);
Manifest manifest = new Manifest(url.openStream());
Attributes mainAttributes = manifest.getMainAttributes();
if (mainAttributes != null) {
Object obj = mainAttributes.get(IMPLEMENTATION_BUILD);
if (obj != null) {
buildNumber = obj;
LOGGER.info("Found P3J Build Number: " + buildNumber);
break;
}
}
}
} catch (Exception e) {
LOGGER.error("Unable to determine build number. {}", e);
}
}
Any advice?
//edit
This code is looking only into manifests in JAR files - my BuildNumber is in WAR file and in Tomcat it is extracted into 'webapps/ROOT/'. But there is still MANIFEST.MF with proper BuildNumber but is not scanned by this code.
How to check content of \webapps\ROOT\META-INF\MANIFEST.MF in Tomcat?
//edit
There is answer but - now I am looking how to do that in Spring Boot application.