Getting the assembly ID in a Java application

Does anyone have a simple suggestion for writing the assembly identifier (generated at compile time) that appears in the application title bar at run time?

Building inside Eclipse, all I need is an identifier, then I can pass it to the header.

+4
source share
4 answers

If you use Ant, you can easily set your jar or package target to create a file, including the current timestamp, and include this in your jar output.

If you use Maven, there are several ways to achieve something similar, for example, go down to Ant using the antrun plugin .

+3
source

if you use maven, especially if you want the build number from svn (although it could generate unique build numbers for you through the configuration), look at buildnumber-maven-plugin .

you simply add a fragment similar to the following to the pom.xml file:

  <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> <version>1.0-beta-3</version> <executions> <execution> <phase>validate</phase> <goals> <goal>create</goal> </goals> </execution> </executions> <configuration> <doCheck>true</doCheck> <doUpdate>true</doUpdate> </configuration> </plugin> 

then use $ {buildNumber} later in your pom to refer to the build id. I use it to write this number in the manifest like this using the maven-war plugin.

  <archive> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> </manifest> <manifestEntries> <Implementation-Build>${buildNumber}</Implementation-Build> </manifestEntries> </archive> 
+4
source

If you want to use the timestamp for the assembly, you can get it from the modification dates of the flag or class or MANIFEST file.

Maven fills the MANIFEST file with the version number of the module in the bank. You can read this to get the version of all maven modules that you use.

Creating a “unique identifier” timestamp ensures that each assembly has a different identifier.

+2
source

If you are completely building inside Eclipse, you need to create an assembly action that generates a resource in your source folder with the necessary information - the properties file will do nicely - which then extends to your binary output and can be read at runtime, after which you can do what you need to show it.

0
source

All Articles