0

I want to use resource files from two jar files. Is it possible ?

build.gradle

sourceSets { main { resources { srcDir 'src/resources' files('libs/myOwnFile-1.jar:src/resources') //add another resource jar file } } } 

This means , I want to include resource files (mainly xml files) also from libs/myOwnFile-1.jar file. The jar is creating by other team but it's another project which cannot be linked with this project. But I know the path of resources (src/resources)

Is it possible to use src/resources under jar file ?

2
  • You mean in gradle script or in project managed by gradle? Could you please clarify the question and add an example? Commented Oct 10, 2015 at 11:07
  • hmm.. sorry @Opal for the confusion. I didnt think that much deep :) I was telling about the script with which I run in console (build.gradle). I will edit the question now. Commented Oct 12, 2015 at 4:53

1 Answer 1

1

If an external JAR contains resources you want to use, consider just adding that JAR as a dependency to your project. That way, you can also use these resources in your own code.

For example, the following code will add all JARs in the libs folder as dependencies:

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) } 

The sourceSets property on the other hand is typically for sources/resources that are part of the project itself (and aren't part of another JAR).

Sign up to request clarification or add additional context in comments.

2 Comments

if so, think I have the same folder structure for my main project and the jar I included and also two files in resources of jar are same file name as in project. Which will have the priority ?
Based on some Googling, the first resource that is defined on the classpath gets priority. If the "main" project already contains such resources, I would expect those to have priority over external resources with the same path.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.