# Adding a local jar to a web app

**URL:** <https://discuss.gradle.org/t/adding-a-local-jar-to-a-web-app/26831>\
**Category:** Help/Discuss\
**Created:** [May 4, 2018, 4:23pm UTC](https://discuss.gradle.org/t/adding-a-local-jar-to-a-web-app/26831 "2018-05-04T16:23:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![blake1024](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/blake1024/32/6948_2.png) [@blake1024](https://discuss.gradle.org/u/blake1024)\
**Post date:** [May 4, 2018, 4:23pm UTC](https://discuss.gradle.org/t/adding-a-local-jar-to-a-web-app/26831/1 "2018-05-04T16:23:26Z")

</div>

Greetings,

New to Gradle here. Sorry about the really basic question.

I am building a web app. I tried the tutorial to build, run locally, and deploy the war. All works fine.

The problem I am having is adding some local jar files. I tried adding my jar files to the src/main/resources directory. They get added to the app root of the war file but the app won’t compile because they’re not in the build classpath. Rather than kludge a result, I thought I’d ask what the correct solution is.

So, in brief, I want to add some local jar files. These jar files must:

1. work at compile time
2. be included in the war
3. be accessible when the war is deployed

Thank you.

Blake McBride

---

<div class="post-metadata">

**Author:** ![blake1024](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/blake1024/32/6948_2.png) [@blake1024](https://discuss.gradle.org/u/blake1024)\
**Post date:** [May 4, 2018, 4:25pm UTC](https://discuss.gradle.org/t/adding-a-local-jar-to-a-web-app/26831/2 "2018-05-04T16:25:59Z")

</div>

Also, in case it helps, here is my build.gradle:

```
plugins {
    id 'war'  
    id 'org.akhikhl.gretty' version '1.4.2'
}

repositories {
    jcenter()
}

dependencies {
    providedCompile 'javax.servlet:javax.servlet-api:3.1.0' 
    testCompile 'junit:junit:4.12'
}
```

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [May 4, 2018, 5:52pm UTC](https://discuss.gradle.org/t/adding-a-local-jar-to-a-web-app/26831/3 "2018-05-04T17:52:51Z")

</div>

Firstly, I suggest that you deploy the jars to a proper repository rather than having local jars in a folder.

Failing that I suggest that you store your files in a maven style directory layout.

Eg

```gradle
myLocalRepo/com/foo/bar/1.0/bar-1.0.jar
myLocalRepo/com/foo/baz/2.0/baz-2.0.jar

```

build.gradle

```gradle
repositories {
   maven {
      uri file('myLocalRepo')
   }
} 
dependencies {
   compile 'com.foo:bar:1.0'
   compile 'com.foo:baz:2.0'
}

```

---

<div class="post-metadata">

**Author:** ![blake1024](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/blake1024/32/6948_2.png) [@blake1024](https://discuss.gradle.org/u/blake1024)\
**Post date:** [May 4, 2018, 7:30pm UTC](https://discuss.gradle.org/t/adding-a-local-jar-to-a-web-app/26831/4 "2018-05-04T19:30:27Z")

</div>

Thanks for the help, Lance. I have two projects that are both under very active development. A repo to hold a jar doesn’t make sense for me just yet. I ended up with the following that does what I need:

```
plugins {
    id 'war'  
    id 'org.akhikhl.gretty' version '1.4.2'
}

repositories {
    jcenter()
}

dependencies {
    providedCompile 'javax.servlet:javax.servlet-api:3.1.0' 
    testCompile 'junit:junit:4.12'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
```

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [May 4, 2018, 7:53pm UTC](https://discuss.gradle.org/t/adding-a-local-jar-to-a-web-app/26831/5 "2018-05-04T19:53:02Z")

</div>

Using files like this the artifacts can’t participate in Gradle’s dependency resolution. You can’t have transitive dependencies in poms and you also can’t associate javadocs and sources with the jars (to be linked in your IDE).

If you’re happy with these shortcomings then `fileTree(...)` is fine. Personally I’d use a maven directory layout instead, when you do move to a proper repository it will be simple
