0

We have a resources folder in our EAR, this folder contains some image,xml and text files. I need to add this folder to our EJBs manifest classpath.

myEAR
|-> resources 
|     |-> myXml.xml
|     |-> mytext.txt
|->lib
|   |-> pojo1.jar
|   |-> pojo2.jar 
|->ejb.jar

currently, my maven ear plugin adds our *.jar to my EJB jar classpath, for example, our ejb.jar manifest look like blowing:

Class-Path: lib/pojo1.jar lib/pojo2.jar

but I need to add our "resources" folder to this classpath too:

Class-Path: resources lib/pojo1.jar lib/pojo2.jar 
Vishal
  • 1,442
  • 3
  • 29
  • 48
Mehran
  • 11
  • 6
  • In EAR file? Simply no. An EAR file is an container and does not contain resources etc. only the containing jar's/war's could contain resources... – khmarbaise May 26 '17 at 08:33
  • I agree, But this is an old project and its EAR contain a resources folder! – Mehran May 26 '17 at 13:58
  • The resources will be packaged into the ear file (If i correctly remember) and that means the files are on the classpath of the EAR... – khmarbaise May 27 '17 at 10:17

2 Answers2

0

Following should work if resources folder is a top level folder in your maven project.

<build>
    <resources>
        <resource>
        <directory>resources</directory>
        </resource>
    </resources> 
</build>

If it is not a top level folder, try to leverage src/main/resources folder which by default puts everything under it into the target artifact.

Shailesh Pratapwar
  • 4,054
  • 3
  • 35
  • 46
  • I hope you have added above in ejb's pom and not in ear pom. If yes, use maven-jar-plugin to control entries in manifest.mf. – Shailesh Pratapwar May 26 '17 at 13:18
  • Hi and thank you for your comment. but it doesn't what is I am looking for! First: my " resources" folder is in my maven ear module and if I add this folder as a in my EJB module or as a then maven add content of the resources to root of JAR or EAR but I need to package my EAR in a way that my resources folder placed in the root of EAR and when I want to load the content of my resource folder I just mention the resource name. – Mehran May 26 '17 at 13:28
  • I mean i like to use tread.getContextClassLoader() .getResource("myXml.xml") and not using the falowwing : tread.getContextClassLoader() .getResource("resources\myXml.xml") thanks again – Mehran May 26 '17 at 13:28
  • Check if this helps https://stackoverflow.com/a/19409280/1352127. You can specify the output directory as per your need. – Shailesh Pratapwar May 26 '17 at 15:22
0

Finally, I find a solution for that. we are adding the resources folder to the classpath by using tag in EJB module POM file:

        <plugin>
            <artifactId>maven-ejb-plugin</artifactId>
            <version>${version.ejb.plugin}</version>
            <configuration>
                <ejbVersion>${version.ejbImpl}</ejbVersion>
                <archive>
                    <manifestEntries>
                         <Class-Path>resources</Class-Path>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
Mehran
  • 11
  • 6