Adding a file to the jar during maven build

I am trying to add a license file to all my banks when I build maven. I have a license for each class file, but I want to add License.txt to each META-INF folder in each bank

My project has a master pom, which has half a dozen modules, these modules have their own modules and, ultimately, get into the project that generates the file / target / <.jar-file>. The build and class licenses work, I just want to add the physical License.txt to the META-INF folder.

My file is stored (relative to the main POM) in / src / resources / src -license.txt. I really need an automatic method to ensure that if / when the license changes, I have to update 50 files, I can just update one, which will then be copied to other places.

I tried using

<build> <sourceDirectory>src</sourceDirectory> <resources> <resource> <directory>src/resources</directory> <targetPath>/META-INF</targetPath> <includes> <include>src-license.txt</include> </includes> </resource> </resources> .... </build> 

But that doesn't sound like a trick. I am also trying to use some alternatives to the exit path, such as $ {project.build.outputDirectory} / META-INF or * / META_INF, also to no avail. Does anyone have any experience on how to do this? Thanks

In addition, I use the maven-license-plugin to ensure that every class file has license information inserted into it, and this works as intended. But then again, inside the class files, I am looking for an external .txt file in each <*. Jar> / META-INF /

+4
source share
1 answer

Using resources from parent relativePath is at least difficult (what if you have a complicated directory structure?).

A simple and understandable way could be to create a separate module containing the src-license.txt file. Then make it dependent on your modules and unzip it (dependency: unpack-dependencies) @ phase of resource generation, inside the target / classes.

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>unpack-license</id> <phase>generate-resources</phase> <goals><goal>unpack</goal></goals> <configuration> <artifactItems> <artifactItem> <groupId>com.acme</groupId> <artifactId>com.acme.license</artifactId> <version>${project.version}</version> </artifactItem> </artifactItems> <outputDirectory>${project.build.outputDirectory}</outputDirectory> </configuration> </execution> </executions> </plugin> 
+3
source

Source: https://habr.com/ru/post/1499684/


All Articles