1

I have one .properties file present on the internet/online (you can say it's an external file). I want to read the properties (versions) from it to update the modules' versions in my .XML file. I searched about the PropertyPlaceholderConfigurer, but it is deprecated. Is there any other way for this?

Properties file:

github.dd-core=6.5.2

XML file:

<modules>
  <module>
      <name>dd-core-6.5.2</name>
      <artifactid>com.dd-core</artifactid>
      <version>6.5.2</version>
  </module>
</modules>

Expected Result: In version tag, instead of 6.5.2 I want to use property github.dd-core to update the version at runtime/dynamically. Thank you.

1 Answers1

1

Did you try the solutions offered here? PropertyPlaceHolderConfigurer Alternative

Otherwise you can perhaps look into the properties plugin, it claims to do a similar thing: https://www.mojohaus.org/properties-maven-plugin/index.html

The properties loaded from files or URLs can be used to filter resources differently for different environments. Those using Spring's PropertyPlaceholderConfigurer can see how these goals can be useful. Note that the URL format accepts Spring's classpath: style pseudo-URL syntax.

Specifically: https://www.mojohaus.org/properties-maven-plugin/read-project-properties-mojo.html

The read-project-properties goal reads property files and URLs and stores the properties as project properties. It serves as an alternate to specifying properties in pom.xml. It is especially useful when making properties defined in a runtime resource available at build time.

slindenau
  • 1,091
  • 2
  • 11
  • 18
  • thanks for your answer. I used https://www.mojohaus.org/properties-maven-plugin/read-project-properties-mojo.html and it is working fine for .properties file present within the same directory of .xml file. But for external file, say I have url as - https://abc.technology.com/myrepo/myfolder/1.2.3.4/xyz.properties, then how to specify it in url tag? – Sagar Sikchi Jun 03 '22 at 20:13
  • classpath:/config/dev.propertiesfile:///${env.HOME}/mydev.properties Can you elaborate on this? – Sagar Sikchi Jun 03 '22 at 20:17
  • @SagarSikchi besides the `classpath` prefix the input URL is just a standard [java.net.URL](https://docs.oracle.com/javase/8/docs/api/java/net/URL.html), so any normal HTTP(S) url will work. – slindenau Jun 04 '22 at 07:49
  • thanks! It worked for me. I forgot to remove the classpath keyword and got errors. But now, it is resolved. – Sagar Sikchi Jun 05 '22 at 10:51
  • Also, @slindenau, if you found this question interesting, then please upvote. It will boost my confidence to always learn new things on Stack Overflow :) Thank you. – Sagar Sikchi Jun 05 '22 at 11:00