Tuesday, May 3, 2016

How to show java web project version using Maven

1. Pom.xml


<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>

<plugin>
<artifactId>maven-war-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.1.1</version>
<configuration>
<archive>
<manifestEntries>
<SCM-Revision>${maven.build.timestamp}</SCM-Revision>
</manifestEntries>
</archive>
</configuration>

</plugin>

2. Java code.

public static String getProjectVersion() {
ServletContext application = Sessions.getCurrent().getWebApp().getServletContext();
InputStream inputStream = application.getResourceAsStream("/META-INF/MANIFEST.MF");
Manifest manifest;
try {
manifest = new Manifest(inputStream);
Attributes attr = manifest.getMainAttributes();
return attr.getValue("SCM-Revision");
} catch (IOException e) {
e.printStackTrace();
}
return "";
}


How to Calculate the Future Investment Value of Investment.

Below java program for calculate future investment value. Here calculate s using the formula futureInvestmentValue =investmentAmount x (...