1

I have a maven web application that has a dependency on an EJB project.

   <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>soar-ejb</artifactId>
        <version>1.0</version>
        <type>jar</type>
    </dependency>

In the EJB project there I've added an env-entry in the ejb-jar.xml as such:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns = "http://java.sun.com/xml/ns/javaee" 
     version = "3.1"
         xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee     http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
    <enterprise-beans>
        <session>
            <env-entry>
                <description>Config file</description>
                <env-entry-name>configFileLocation</env-entry-name>
                <env-entry-type>java.lang.String</env-entry-type>
                <env-entry-value>dropbox-config.properties</env-entry-value>
            </env-entry>
        </session>
    </enterprise-beans>
</ejb-jar>

I've tested the EJB project, using arquillian, and I am able to inject this value using @Resource as such: @Resource(name = "configFileLocation") private String configFile;

Now, when I build the .war with the ejb dependency, I get a .war with my EJB project as a .jar inside WEB-INF\lib. Within this EJB project (i.e. inside the .jar) the ejb-jar.xml file is in the proper META-INF directory.

BUT now, when I deploy to the server the @Resource injection never works. The String is always null. According to what I have read I have the ejb-jar.xml in the correct location, both within the EJB project and within the .war that maven produces.

Would someone have an idea of what I've configured incorrectly?

Thanks!

EDIT:

Modified the session element to

<session>
        <description>An EJB that loads configuration from a file</description>
        <display-name>ConfigurationProducer</display-name>
        <ejb-name>ConfigurationProducer</ejb-name>
        <ejb-class>com.trf.util.DropboxConfigFileProducer</ejb-class>
        <session-type>Stateless</session-type>
        <env-entry>
            <description>Location of the config file</description>
            <env-entry-name>configFileLocation</env-entry-name>
            <env-entry-type>java.lang.String</env-entry-type>
            <env-entry-value>dropbox-config.properties</env-entry-value>
        </env-entry>
    </session>
flchannel
  • 33
  • 1
  • 10

2 Answers2

1

I solved this by modifying the dependency for the ejb project in pom.xml to be provided and then wrapping the war and ejb projects into an ear project. pom.xml of the web archive now looks like this:

    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>soar-ejb</artifactId>
        <version>1.0</version>
        <scope>provided</scope>
    </dependency>

Then in the ear project's pom.xml we have this:

 <dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>soar-ejb</artifactId>
        <version>1.0</version>
        <type>ejb</type>
    </dependency>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>soar-war</artifactId>
        <version>1.0</version>
        <type>war</type>
    </dependency>
</dependencies>

@Resource injection is now working on the env-entries in the ejb's ejb-jar.xml when I deploy to the server from the ear project !

flchannel
  • 33
  • 1
  • 10
0

The session element of your ejb-jar.xml doesn't contain the ejb-name property, try to put one with the name matching the bean interface name. I've edited your answer to show you an example.

remigio
  • 4,101
  • 1
  • 26
  • 28
  • Remigo, I've added the ejb-name element to the session element and the resource is still not getting injected. Still works when I test the ejb project by itself. – flchannel Jun 05 '13 at 12:34