3

I'm not an expert on Maven, so I'm sorry if this question is a bit silly.

I am using 3 descriptors in my pom.xml. In each of these descriptors, a file is being filtered. I would like to use a placeholder to reference the id of the descriptor from inside the file.

For example, if this is one of my assembly descriptors:

<assembly>
    <id>descriptorNumberTwo</id>
    ...

    <file>
        <source>src/main/assembly/run.sh</source>
        <fileMode>0755</fileMode>
        <lineEnding>unix</lineEnding>
        <filtered>true</filtered>
    </file>
    ...
</assembly>

I want to use ${placeholder.for.my.id} (or something) in my run.sh, to get "descriptorNumberTwo". Is this possible?

Thanks in advance!!

Jester
  • 56,577
  • 4
  • 81
  • 125
Lucía
  • 143
  • 1
  • 8
  • You probably should use the "normal" resource filtering so that Maven places it under `target/something`, then reference that location in the assembly. Better assemble from processed resources than from sources. – Tome Apr 29 '15 at 14:15
  • Thanks for the answer. All the descriptors are filtering the same file. So I want my first zip to have a run.sh with "descriptorNumberOne", the second zip with a run.sh saying "descriptorNumberTwo" and so on. So I don't think I can use the properties from the pom.xml. – Lucía Apr 29 '15 at 15:04
  • 1
    In that case, yes, what you describe is possible. But you may need to use a specific properties file, as specified here: https://maven.apache.org/plugins/maven-assembly-plugin/examples/single/filtering-some-distribution-files.html – Tome Apr 29 '15 at 16:49
  • Thanks for the help! I still don't see how I could do it. Can you somehow choose which properties file you want to use for each descriptor? In the example, the properties file is being added in the pom, so the values would be the same for all the descriptors, right? (Excuse my English!) – Lucía Apr 29 '15 at 17:14
  • Oh, there is, I didn't know you could do that. This is great, thanks Tome! http://olafsblog.sysbsb.de/per-assembly-filtering-with-the-maven-assembly-plugin/ – Lucía Apr 29 '15 at 17:50
  • 1
    Yes indeed, if you need 3 different values for the same property, profiles can be used. That means only one assembly will be generated. But if you need to produce the 3 assemblies in a single Maven command, you'll better use multiple executions, like explained here: http://stackoverflow.com/questions/8726884/create-multiple-runnable-jars-with-depencies-included-from-a-single-maven-proj. And for each execution, specify another ``. – Tome Apr 30 '15 at 07:02

0 Answers0