2

I know its not a good practice to put a properties file inside the jar but our scenario dictates that requirement. What i want is to put the contents of resources folder inside the jar as is. In my maven project, the contents of resources are added in the jar but at the root of the jar. What I need is to have a jar with this structure:

jar root
|__com
|      |_mycompany
|              |____my java files are here as expected
|__resources
         |__my properties files and config files should be here

What i get is:

jar root
|__com
|        |__mycompany
|               |____my java files are here as expected
|
|__my properties files and config files

I know I can add the resources folder as the source folder in eclipse but I need a solution based on maven.

Thanks in advance.

Hammad Dar
  • 475
  • 8
  • 18

2 Answers2

3

You can configure the resources plugin to do that for you:

Here's a sample.

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.test</groupId>
  <artifactId>dummyJar</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>dummyJar</name>
  <dependencies>
  </dependencies>
  <build>
  <plugins>
    <plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <configuration>
        <outputDirectory> ${project.build.outputDirectory}\resources</outputDirectory>
    </configuration>

    </plugin>
  </plugins>
  </build>
</project>
Yogesh_D
  • 17,656
  • 10
  • 41
  • 55
-1

Quick hack is to put your resources in

src/main/resources/resources/
jmj
  • 237,923
  • 42
  • 401
  • 438
  • Thats the last resort though but i need a cleaner solution. – Hammad Dar Aug 24 '14 at 22:32
  • 1
    You can also use assembly plugin to create jar, that would give you lots of flexibility and you can configure assembly plugin to place resources into `resources` directory in side jar without having to do above – jmj Aug 25 '14 at 00:03