How do I include subproject resources in the parent project?

I have a multi-project build Gradle, containing 3 projects: A

, B

and C

.

A

and B

depends on C

.
C

has a file myconfig.xml

in its folder resources

that I would like to include as a resource in a war generated for A

and B

.

A -- project type - WAR
  -- depends on - C
B -- project type - WAR
  -- depends on - C
C -- project type - JAVA
\_ src\main\resources
 \_ myconfig.xml

      

However, just having C as a dependency for A and B doesn't seem to do it. The file is myconfig.xml

missing from the war file folder WBE-INF\classes

. This is indeed present in the file C.jar

, but not where it is needed.

How can I share the resource folder C

to have it in the war file A

and B

?

+3


source to share


4 answers


I'm not sure how it works in gradle, but in maven you can do it using the maven-dependency-plugin:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <configuration>
            <artifactItems>
                <artifactItem>
                    <groupId>yourgroupid</groupId>
                    <artifactId>C</artifactId>
                    <version>${project.version}</version>
                    <type>jar</type>
                    <overWrite>true</overWrite>
                    <outputDirectory>${project.build.directory}/WEB-INF/classes</outputDirectory>
                    <includes>myconfig.xml</includes>
                </artifactItem>
            </artifactItems>
        </configuration>
        <executions>
            <execution>
                <phase>compile</phase>
                <goals>
                    <goal>unpack</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

      



There should be something similar in gradle, maybe there could be a pointer.

+3


source


Consider accessing the xml directly from C.jar as it is on the classpath. You can open the resource as a stream. Check this post Reading resource file from jar



+2


source


Can you explain how you read the myconfig.xml file? If you try to use it getClass().getResourceAsStream("/myconfig.xml")

, you will read it regardless of whether it is in a folder WEB-INF/classes

or in a jar on the classpath. Obviously, it's better to put resources in jars in folders (eg :) my-c-lib/myconfig.xml

to avoid collisions.

+1


source


To use a resource from another project, we must import this project into our classpath.

To import usage, <classpathentry combaccessrules = "false" kind = "src" path = "/ your project c path" / ">

Add this entry to your classpath file (.classpath file) A and B

-1


source







All Articles