0
votes

I have an EAR which at the moment contains only one WAR. My issue is if the mybatis-....jar files locate under web-module.war\WEB-INF\lib then everything works fine. BUT if I create a skinny war with maven and the two mybatis related jars locate under EAR/lib I get a "There are no SqlSessionFactory producers properly configured." error.

I seems that it is a classpath related issue.

I am planning to add more WAR into my EAR and I would like to avoid the situation to put these two jars into each WARs.

Environment: Java 8, Payara Server 4.1.2.172

This is the structure of my EAR, but it does not work

EAR
  +-- lib
       + mybatis-3.4.4.jar
       + mybatis-cdi-1.0.0.jar

  +-- web-module.war

The web module contains a servlet with an injected EJB. This EJB uses myBatis mapper.

Servlet

@WebServlet("/echo")
public class EchoServlet extends HttpServlet {
    @EJB
    private EchoService echoService;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        try (PrintWriter writer = resp.getWriter()) {
            writer.println(echoService.echo("lorempisum"));
        }
    }
}

EJB

@Stateless
public class EchoBean implements EchoService {

    @Inject
    private AccountDao accountDao;

    @Override
    public String echo(String text) {
        List<String> emails = accountDao.findAll();
        return "Hello " + text + "! There are " + emails.size() + " emails in the DB.");
    }
}

MyBatis mapper

@Mapper
public interface AccountDao {
    @Select("SELECT email FROM dev.account")
    List<String> findAll();
}

If I change the structure of my EAR then my project works fine.

EAR
  +-- lib

  +-- web-module.war
       +-- WEB-INF
            +-- lib
                 +-- mybatis-3.4.4.jar
                 +-- mybatis-cdi-1.0.0.jar

I tried to add MANIFEST.MF file to ear\web-module.war\META-INF directory with the following content but it did not help:

Class-Path: lib/mybatis-3.4.4.jar lib/mybatis-cdi-1.0.0.jar

I also tried to add glassfish-web.xml file to ear\web-module.war\WEB-INF directory as described here but it did not help:

<glassfish-web-app>
    <class-loader delegate="true" extra-class-path="../lib/mybatis-3.4.4.jar:../lib/mybatis-cdi-1.0.0.jar"/>
</glassfish-web-app>

Any idea how to solve this classpath issue?

2

2 Answers

-1
votes

I don't remember exactly whether it was the reason why we eventually came to this but: having your EAR components unpacked (simple folders for wars and ejbs inside ear archive) could help.

Here is the config with Maven:

<plugin>
    <artifactId>maven-ear-plugin</artifactId>
    <configuration>
        <applicationName>myApp</applicationName>
        <version>6</version>
        <filtering>true</filtering>
        <initializeInOrder>true</initializeInOrder>
        <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
        <unpackTypes>war,ejb</unpackTypes>
        <modules>
            <ejbModule>
                <groupId>com.example</groupId>
                <artifactId>myapp-ejb</artifactId>
                <bundleFileName>myapp-ejb.jar</bundleFileName>
            </ejbModule>
            <webModule>
                <groupId>com.example</groupId>
                <artifactId>myapp-rest</artifactId>
                <contextRoot>/myapp</contextRoot>
                <bundleFileName>myapp.war</bundleFileName>
            </webModule>
        </modules>
    </configuration>
</plugin>