2

I have an ear file with a web module and a ejb module(just used for message driven beans). The ejb module has dependency on web module and it's classes. I would need to load the web module first and then ejb module. But the liberty always loading the ejb module first causing com.ibm.ws.container.service.state.StateChangeException: java.lang.NoClassDefFoundError:

How to control the order of modules loading within the same ear file? On traditional webshpere there is an option called 'Starting weight'. Whichever module has lowest value takes precedence and loads it first. so the application works good on tradition Websphere. However, this property seems missing on Liberty. I already looked at this. It only talks about deploying the multiple war files and their order.

2 Answers2

1

If your EJB module depends on Web, that is bad design. It should be the other way around.

If you have such situation , proper way would be to extract shared classes in to a common jar file, let say mycommon.jar and then put that into ear\lib folder. In this way they will be visible by both modules ejb and web.
If your EJB module depends on the javax web api (e.g. servletRequest) that is even worse, and you should redesign such classes to POJO DTOs.

As a last resort you could try what is described here and add <initialize-in-order>true</initialize-in-order> in your application.xml.

FRowe's solution will not work, as classes are not shared between the applications, so changing load order of apps will not help. Each Java™ EE application has its own class loader in a running Liberty server.

Gas
  • 17,601
  • 4
  • 46
  • 93
  • 1
    @Gas- Thank you for your answer. Agree that Web should depend on EJB but not other way around. However, that's how its there for more than a decade and stable in production. Changing all that is a huge task. So trying to do a quick fix without major changes. I was hopeful on specifying true in application.xml should work as it also says here https://www.ibm.com/docs/en/was-nd/8.5.5?topic=beans-ejb-module-settings under Starting Weight section. Unfortunately, that is not working for liberty. Anything else I can try? – user14101754 May 13 '21 at 21:13
  • 2
    @user14101754 what you could try is to embed EJBs in the web module. It is possible since JEE6. Then all classes will be loaded by the same classloader, so will be visible. So if your app is just these 2 modules it could be a solution, and repackaging changes would be smaller comparing to creating shared lib. – Gas May 14 '21 at 00:08
  • Making the ejb part of the war worked though I had to resolve other class loading issues especially related cxf - Thank you. I believe even the shared directory between those 2 module also works. Except this one true(as its not working for liberty), I'm accepting your answer as a solution. – user14101754 May 14 '21 at 19:50
0

Consider using the ability to control app start order as described here: https://www.openliberty.io/blog/2020/06/05/graphql-open-liberty-20006.html?_ga=2.4728563.17466047.1620833568-1423690488.1614284842&cm_mc_uid=99965752544816136653536&cm_mc_sid_50200000=61078141620909829332#ORDER You'll have to deploy the war module as an app instead of packaging it within the ear, but you should be able to achieve the proper ordering.

F Rowe
  • 2,042
  • 1
  • 11
  • 12
  • Both web and ejb modules are part of same ear, they should share the classes loaded(similar to 'single class loader policy' on websphere). So it doesn't work that way. – user14101754 May 13 '21 at 21:18