0

I want to generate a resource file containing information from pom.xml that I can then load in my Java application. I followed this and this. I can generate .properties file with some information substituted but not license information.

I have this section in my pom.xml:

<licenses>
    <license>
        <name>MIT license</name>
        <url>https://spdx.org/licenses/MIT.html</url>
        <distribution>manual</distribution>
        <comments>A short and to the point license that allows almost anything</comments>
    </license>
</licenses>

And then I want to do this:

licenseName = ${project.licenses.license.name}
licenseUrl = ${project.licenses.license.url}

but the values do not get replaced.

Googling suggests using some plugins that handle licenses, but that is too much for my use case.

Thank you.

  • Just a wild guess: You maybe need to specify that you want the first license from the list. – J Fabian Meier Jun 10 '21 at 09:02
  • The licenses is a list of license so you have to specify which one you like to access `${project.licenses[0].name}` (not 100% sure if that way..).. – khmarbaise Jun 10 '21 at 09:32
  • I was thinking that may be it, but I cannot find how to do that. License plugins or resource management plugins always pop up when serching online. I might be missing the correct terminology. Could you please provide a link at the very least since I cannot find suitable sources of information? – TurgonTheKingOfGondolin Jun 10 '21 at 09:35
  • What exactly are you trying to try? Get all licenses into a file? For example: https://www.mojohaus.org/license-maven-plugin/ – khmarbaise Jun 10 '21 at 09:37
  • Sorry, I had written that previous comment before @khmarbaise wrote theirs. And the suggestion does not work. I want to load the name and the url to code so I can display it in "about" window of my app. – TurgonTheKingOfGondolin Jun 10 '21 at 09:44
  • The license plugin creates an XML which you can simply parse and use it... and will do what you want during the build process.. – khmarbaise Jun 10 '21 at 10:02
  • Thanks, I will consider that, but it still seems to me that the most effective way would be figuring out this indexing thing, but I cannot find any information on how to do it. – TurgonTheKingOfGondolin Jun 10 '21 at 10:13
  • I don't think so because every time you change the licensing (change add a dependency) You build setup needs to be changed as well. If you simply run the license plugin which generates an xml file which can be packaged into the app and read and it does not matter how many entries are in there... – khmarbaise Jun 10 '21 at 10:59
  • Ok, I will give it a go. – TurgonTheKingOfGondolin Jun 10 '21 at 11:58

0 Answers0