# How do I specify the resources folder in a Jar?

**URL:** <https://discuss.gradle.org/t/how-do-i-specify-the-resources-folder-in-a-jar/16054>\
**Category:** Help/Discuss\
**Created:** [April 6, 2016, 2:28pm UTC](https://discuss.gradle.org/t/how-do-i-specify-the-resources-folder-in-a-jar/16054 "2016-04-06T14:28:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![moaxcp](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@moaxcp](https://discuss.gradle.org/u/moaxcp)\
**Post date:** [April 6, 2016, 2:28pm UTC](https://discuss.gradle.org/t/how-do-i-specify-the-resources-folder-in-a-jar/16054/1 "2016-04-06T14:28:35Z")

</div>

I am converting a project from ant to gradle. The ant project puts resources in to a resources folder in the jar. I want to do the same in gradle.

This is the project structure

```
project
+-- sources
+-- resources
    +-- config.properties
+-- test

```

This is the source sets

```
sourceSets {
    main {
        java {
            srcDir 'source'
        }
        resources {
            srcDir 'resources'
            include 'config.properties'
        }
    }
    test {
        java {
            srcDir 'test'
        }
    }
}

```

The resulting jar looks like this

```
project.jar
+-- com
+-- META-INF
+-- config.properties

```

I need the resulting jar to put `config.properties` in `resources`

```
project.jar
+-- com
+-- META-INF
+-- resources
    +-- config.properties

```

I was hoping that by adding an `into` under the `include` I could get what I want but that did not work. Is there any simple way to specify the folder resources go into when my project is built? I tried the `output.resourcesDir` but that only changed the location in the buildDir not the jar. I’m hoping for a simple feature that does this. I’m currently using gradle 2.4 but hope to upgrade to 2.12 soon.

---

<div class="post-metadata">

**Author:** ![Lance\_Java](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance_java/32/787_2.png) [@Lance\_Java](https://discuss.gradle.org/u/Lance_Java)\
**Post date:** [April 6, 2016, 3:17pm UTC](https://discuss.gradle.org/t/how-do-i-specify-the-resources-folder-in-a-jar/16054/2 "2016-04-06T15:17:04Z")

</div>

The simplest solution would be to make another nested resources folder and move the existing prop files. Eg:

```gradle
project
+-- sources
+-- resources
    +-- resources
        +-- config.properties

```

This would mean that you could interchangably put either the jar file or the (top level) resources folder on the classpath without issues (eg test cases)

---

<div class="post-metadata">

**Author:** ![Schalk\_Cronje](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schalk_cronje/32/6511_2.png) [@Schalk\_Cronje](https://discuss.gradle.org/u/Schalk_Cronje)\
**Post date:** [April 6, 2016, 3:23pm UTC](https://discuss.gradle.org/t/how-do-i-specify-the-resources-folder-in-a-jar/16054/3 "2016-04-06T15:23:44Z")

</div>

Remove the resources block and just configure the `jar` task appropriately:

```groovy
jar {
  into 'resources', {
    from 'resources'
  }
}

```

---

<div class="post-metadata">

**Author:** ![moaxcp](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@moaxcp](https://discuss.gradle.org/u/moaxcp)\
**Post date:** [April 6, 2016, 6:42pm UTC](https://discuss.gradle.org/t/how-do-i-specify-the-resources-folder-in-a-jar/16054/4 "2016-04-06T18:42:35Z")

</div>

Lance\_Java, That is not possible right now. We are trying to replace a legacy ant build and that would break it.

Schalk\_Cronje, I will try that and let you know.

---

<div class="post-metadata">

**Author:** ![moaxcp](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@moaxcp](https://discuss.gradle.org/u/moaxcp)\
**Post date:** [April 7, 2016, 3:54pm UTC](https://discuss.gradle.org/t/how-do-i-specify-the-resources-folder-in-a-jar/16054/5 "2016-04-07T15:54:42Z")

</div>

Hey this worked great. Thanks for the tip!

---

<div class="post-metadata">

**Author:** ![paolopavan](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@paolopavan](https://discuss.gradle.org/u/paolopavan)\
**Post date:** [November 8, 2019, 11:02pm UTC](https://discuss.gradle.org/t/how-do-i-specify-the-resources-folder-in-a-jar/16054/6 "2019-11-08T23:02:45Z")

</div>

Hi,  
I have the same issue here, can you please help to understand what goes wrong with my build file reported below?  
I am using Gradle 5.2.1  
Thanks a lot

```gradle
plugins {
    id 'java'
}

repositories {
    mavenCentral()
}

sourceSets {
    main {
        java {
            srcDirs = ['src']
        }
    }

    test {
        java {
            srcDirs = ['test']
        }
    }
}

dependencies {
    compile 'commons-logging:commons-logging:1.1.3'
    compile 'org.jetbrains:annotations:13.0'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
}

jar {
    into 'resources', {
        from 'resources'
    }
}

test {
    useJUnitPlatform()
}

```

---

<div class="post-metadata">

**Author:** ![Schalk\_Cronje](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schalk_cronje/32/6511_2.png) [@Schalk\_Cronje](https://discuss.gradle.org/u/Schalk_Cronje)\
**Post date:** [November 9, 2019, 9:37pm UTC](https://discuss.gradle.org/t/how-do-i-specify-the-resources-folder-in-a-jar/16054/7 "2019-11-09T21:37:04Z")

</div>

What are you seeing?

---

<div class="post-metadata">

**Author:** ![paolopavan](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@paolopavan](https://discuss.gradle.org/u/paolopavan)\
**Post date:** [November 11, 2019, 1:47pm UTC](https://discuss.gradle.org/t/how-do-i-specify-the-resources-folder-in-a-jar/16054/8 "2019-11-11T13:47:28Z")

</div>

Thank you! Simply the resources are located at the root level of my jar package while I was expecting them grouped in a “resource” directory.  
Should I also manually manage the copy of those resources in the build directory with a custom copy task?

---

<div class="post-metadata">

**Author:** ![paolopavan](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@paolopavan](https://discuss.gradle.org/u/paolopavan)\
**Post date:** [November 15, 2019, 8:26pm UTC](https://discuss.gradle.org/t/how-do-i-specify-the-resources-folder-in-a-jar/16054/9 "2019-11-15T20:26:54Z")

</div>

A custom copy task as the one reported below is in fact able to solve the issue and I have obtained what I expected described in my previous post. Anyway, for the sake of completeness, I will be grateful if someone can explain:

1. does Gradle in default config package resources at root level of the jar file or I can suppose that there is still something inusual in my setup?
2. there is any philosophical reason to package all the resources at root level of a jar?

Can someone point to a relevant documentation, please?  
Thank you

```gradle
task copyResources(type: Copy) {
    from "${projectDir}/src/main/resources"
    into "${buildDir}/classes/java/main/resources"
}
processResources.dependsOn copyResources

```

---

<div class="post-metadata">

**Author:** ![Schalk\_Cronje](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schalk_cronje/32/6511_2.png) [@Schalk\_Cronje](https://discuss.gradle.org/u/Schalk_Cronje)\
**Post date:** [December 9, 2019, 1:33pm UTC](https://discuss.gradle.org/t/how-do-i-specify-the-resources-folder-in-a-jar/16054/10 "2019-12-09T13:33:22Z")

</div>

> [@paolopavan](#):
>
> jar { into ‘resources’, { from ‘resources’ } }

Maybe you should fix this `jar` task to be

````gradle
jar {
    from 'resources', {
        into 'resources'
    }
}```
````
