Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: how to place resource file together with jar?

I have \src\main\resources\logback.xml file. When I run mvn package it is placed into the jar by default. How do I make Maven place it next to jar, not inside?

So, well, I just want Maven to copy the resource to the same folder where jar will be.

like image 968
Vladislav Rastrusny Avatar asked Apr 12 '11 15:04

Vladislav Rastrusny


People also ask

How do I add resources to my jar Maven?

To include a resource, we only need to add an <includes> element. And to exclude a resource, we only need to add an <excludes> element. For example, if we want to include all text and RTF files under our src/my-resources directory and in all its subdirectories, we can do the following: <project>

How do I add a resource file to a jar file?

1) click project -> properties -> Build Path -> Source -> Add Folder and select resources folder. 2) create your JAR!

Can jar contain resources?

jar ) contain your executable classes and resource files. A jar can also contain other jar files, which is useful when your program needs some library which is packaged in a jar.


1 Answers

No plugin definitions needed, just edit the build resources:

<build>     <resources>         <!-- regular resource processsing for everything except logback.xml -->         <resource>             <directory>src/main/resources</directory>             <excludes>                 <exclude>logback.xml</exclude>             </excludes>         </resource>         <!-- resource processsing with a different output directory              for logback.xml -->         <resource>             <directory>src/main/resources</directory>             <includes>                 <include>logback.xml</include>             </includes>             <!-- relative to target/classes                  i.e. ${project.build.outputDirectory} -->             <targetPath>..</targetPath>         </resource>     </resources> </build> 

Reference:

like image 98
Sean Patrick Floyd Avatar answered Sep 19 '22 03:09

Sean Patrick Floyd