How To Get At&t Installation Fee Waived
How to get the pom properties at runtime?
I recently needed to admission some of the pom properties at runtime. To be more specific, I needed the version related properties: artifact id, group id, and version. Information technology turned out that there are at least three ways practise that.
Each of the three approaches has its upsides and downsides. You feel free to pick the one that suits you the best.
Get the version info from the manifest
The correct identify to observe the version info is the manifest of the jar file. Maven unfortunately does not add it there by default. You can instruct maven to do that for you by properly configuring the maven-jar-plugin.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>org.programirame.Chief</mainClass> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> </manifest> </annal> </configuration> </plugin>
The important moment here is to gear up the <strong>addDefaultImplementationEntries</potent> value to true. This tells maven to add the following values to the manifest file:
- Implementation-Championship: ${project.proper name}
- Implementation-Version: ${projection.version}
- Implementation-Vendor-Id: ${project.groupId}
- Implementation-Vendor: ${project.organization.proper noun}
- Implementation-URL: ${project.url}
After the jar artifact is congenital in this manner, getting the info in the code is easy:
Package mainPackage = Main.class.getPackage(); String version = mainPackage.getImplementationVersion(); String groupId = mainPackage.getName(); String artifactId = mainPackage.getImplementationTitle();
This maybe is a bit more difficult to test but it is a very piece of cake and straightforward. Nevertheless, if you need to admission whatsoever other pom properties, this won't work.
Go the pom properties using filtering
Maven has the option of filtering. Information technology allows yous to replace variables in your resource files with actual values of pom properties. Start, create a pom.properties file in your resource folder. The name of the file is arbitrary. Add the variables yous need to the file:
artifactId=${project.artifactId} groupId=${project.groupId} version=${project.version} Next, configure the resource section of the build stage:
<build> <resources> <resources> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/pom.properties</include> </includes> </resource> <resource> <directory>src/primary/resource</directory> <filtering>imitation</filtering> <excludes> <exclude>**/pom.properties</exclude> </excludes> </resources> </resources> ..... </build>
This instructs maven to get over the pom.backdrop files and change all the variables with actual values. Afterwards you build the projection the file tin be found in the resulting jar, containing all the existent values. All y'all need to practice so is read the property file as yous would read any other property file in java:
Properties properties = new Properties(); properties.load(Main.grade.getResourceAsStream("/pom.backdrop")); String version = properties.getProperty("version"); String artifactId = backdrop.getProperty("artifactId"); String groupId = properties.getProperty("groupId"); Get the pom properties using the properties plugin
Maven has a <a href="http://www.mojohaus.org/backdrop-maven-plugin/usage.html">dedicated plugin</a> for getting pom properties in and out of files. This is how you configure writing the properties to a file names version.properties:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>backdrop-maven-plugin</artifactId> <version>ane.0.0</version> <executions> <execution> <phase>generate-resources</phase> <goals> <goal>write-project-properties</goal> </goals> <configuration> <outputFile> ${project.build.outputDirectory}/version.properties </outputFile> </configuration> </execution> </executions> </plugin> This volition write all properties defined in the properties section of the pom into the version.properties file. But this has its downside. If you desire a property to announced in the file, you will have to ascertain it in the properties section. The version info does not appear there by default.
Recommended for you
Source: https://igorski.co/how-to-get-the-pom-properties-at-runtime/
Posted by: armstrongmasimed.blogspot.com

0 Response to "How To Get At&t Installation Fee Waived"
Post a Comment