samedi 26 juillet 2014

Java - déterminer la version de l'application web déployée - Stack Overflow


I am developing web application on Java platform using JSF, Maven build, SVN.


I have already included the application version number, revision, date extra on the jar/war manifest using maven plugin.


How can I find the version number of the deployed application from the browser using page view source (if I want hide this from the end user) ?


stackoverflow.com display the version details at the footer e.g. rev 2013.10.20.1076.




Another possible alternative is as follows:


Use versions:set -DnewVersion={{YOUR_VERSION_NUMBER}} to set the version.


Then in the maven-war-plugin:


       <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifestEntries>
<your-version>${project.version}</your-version>
</manifestEntries>
</archive>
</configuration>
</plugin>

Finally, you can use jcabi-manifests to do further processing.




You can use this maven plugin :


        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<!-- Impossible de filtrer les ressources web de l'application avec le plugin v2.0.2 Nécessaire pour 'versioner' les .css, .js Maven 2.x WAR Plugin MWAR-134 -->
<version>2.1.1</version>
<configuration>
<!-- Maven 2.x WAR Plugin MWAR-187 regression running war packaging with maven 2.1 Stephane Nicoll added a comment - 07/Jul/09 3:28 AM One way to quickly work around this issue is to deactivate the cache. -->
<useCache>false</useCache>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<!-- Filtering activates replacement of ${pom.version} in *.xhtml... -->
<filtering>true</filtering>
<!-- I've chosen to exlude manually these resources from the filtering -->
<excludes>
<exclude>**/*.xml</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>

Then you can insert this in the base xhtml template for your application (well... in something that ends up in all your pages if you want it on all pages) :


<span style="display:hidden">${pom.version}"</span>

Note : this will work on a maven-built war. If you don't use maven while testing your webapp with Eclipse for instance, you'll still have ${pom.version} not replaced.




You can create some text static file with content:


version: ${pom.version}
build time: ${build.time}
svn revision: ${svn.revision}
svn path: ${svn.path}
committed date: ${svn.committedDate}

and put it to src\main\webapp\about\info.txt, use com.google.code.maven-svn-revision-number-plugin to provide values for above variables:


<build>
<plugins>
.......
<plugin>
<groupId>com.google.code.maven-svn-revision-number-plugin</groupId>
<artifactId>svn-revision-number-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<entries>
<entry>
<prefix>svn</prefix>
</entry>
</entries>
</configuration>
</plugin>
.....
</plugins>
.........
</build>

The file will be available under http://your-domain.com/resources/about/info.txt



I am developing web application on Java platform using JSF, Maven build, SVN.


I have already included the application version number, revision, date extra on the jar/war manifest using maven plugin.


How can I find the version number of the deployed application from the browser using page view source (if I want hide this from the end user) ?


stackoverflow.com display the version details at the footer e.g. rev 2013.10.20.1076.



Another possible alternative is as follows:


Use versions:set -DnewVersion={{YOUR_VERSION_NUMBER}} to set the version.


Then in the maven-war-plugin:


       <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifestEntries>
<your-version>${project.version}</your-version>
</manifestEntries>
</archive>
</configuration>
</plugin>

Finally, you can use jcabi-manifests to do further processing.



You can use this maven plugin :


        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<!-- Impossible de filtrer les ressources web de l'application avec le plugin v2.0.2 Nécessaire pour 'versioner' les .css, .js Maven 2.x WAR Plugin MWAR-134 -->
<version>2.1.1</version>
<configuration>
<!-- Maven 2.x WAR Plugin MWAR-187 regression running war packaging with maven 2.1 Stephane Nicoll added a comment - 07/Jul/09 3:28 AM One way to quickly work around this issue is to deactivate the cache. -->
<useCache>false</useCache>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<!-- Filtering activates replacement of ${pom.version} in *.xhtml... -->
<filtering>true</filtering>
<!-- I've chosen to exlude manually these resources from the filtering -->
<excludes>
<exclude>**/*.xml</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>

Then you can insert this in the base xhtml template for your application (well... in something that ends up in all your pages if you want it on all pages) :


<span style="display:hidden">${pom.version}"</span>

Note : this will work on a maven-built war. If you don't use maven while testing your webapp with Eclipse for instance, you'll still have ${pom.version} not replaced.



You can create some text static file with content:


version: ${pom.version}
build time: ${build.time}
svn revision: ${svn.revision}
svn path: ${svn.path}
committed date: ${svn.committedDate}

and put it to src\main\webapp\about\info.txt, use com.google.code.maven-svn-revision-number-plugin to provide values for above variables:


<build>
<plugins>
.......
<plugin>
<groupId>com.google.code.maven-svn-revision-number-plugin</groupId>
<artifactId>svn-revision-number-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<entries>
<entry>
<prefix>svn</prefix>
</entry>
</entries>
</configuration>
</plugin>
.....
</plugins>
.........
</build>

The file will be available under http://your-domain.com/resources/about/info.txt


0 commentaires:

Enregistrer un commentaire