2

at time i try to add third party libraries in a EJB-JAR. So far it seems to me, that it is not possible, but i am not sure, and why it is not possible.

I want to create single EJB-JARs and WARs, without put them together in one EAR.

Arjan Tijms shows in Java EE - EAR vs separate EJB+WAR three ways, and to clearify it, i want option 2.

My own research comes mostly to questions with following answers J2EE: How to package 3rd party JARs into an EJB jar?, but i don't want an EAR file.

On the oracle site itself shows following packaging for an EJB-JAR: EJB packaging, which don't have a own lib directory like a WAR. I already tried to put the libary in the root directory (Using eclipse + JBoss 7). My first question is, is it possible to add extra libaries into a EJB-JAR, like in a WAR file? This confuses me, because it is possible to deploy a simple EJB-JAR to a application server, but it seems you cannot add third party libaries. For me a EAR seems mostly "overkill", because it have for me no real advantage and second, if i put a library into a EAR, different EJB-JARs connot use different versions from third party libraries. I want the EJB-JAR complete independent from other EJB-JARs and WARs. I only created a additional simple jar project that contains the interfaces, that have to be implemented, and is added to each EJB project and the WAR project. That brings me to question 2: Have i use to an EAR, if yes, why? It seems to me that i missing something oder don't understand yet.

Community
  • 1
  • 1
user2680083
  • 125
  • 1
  • 2
  • 10
  • 1
    You are trying very hard to do it without an .ear. It's not overkill, it is the solution of your problem. You have already found the related question, it works, just do it. – Beryllium Aug 14 '13 at 09:43
  • Hello Beryllium, what if some EJB-JARs need different Versions of third party libraries. Should use different EARs? – user2680083 Aug 15 '13 at 11:56
  • Maybe there is a way to define separate class loaders for each ejb-jar, but it's asking for trouble. Again instead of trying to find a special way around it, I suggest using only **one** version of a specific jar. – Beryllium Aug 15 '13 at 15:54

2 Answers2

3

You can put third party JARs in a lib/ folder in the EAR and add

<library-directory>lib</library-directory>

to your application.xml.

Philippe Marschall
  • 4,452
  • 1
  • 34
  • 52
  • Thx, but the point is, i don't want to use an EAR, because it have so far, for me, no advantage (exception the possibility to add libraries), and the problem, that for each EJB-JAR in the EAR, all library versions are the same. If you know that a EJB-JAR cannot contains third party libraries, then tell me please, i havn't found yet a clear answer to it. – user2680083 Aug 14 '13 at 11:14
  • 1
    Then put them into `WEB-INF/lib`. – Philippe Marschall Aug 14 '13 at 11:19
  • 1
    Yes it does when you put the EJB-JAR and the 3rd party lib into the `WEB-INF/lib` folder of the `WAR`. You can't deploy EJB-JARs per se, you'll have to package them in a `EAR` or `WAR` (well several servers allow it but it's not portable). – Philippe Marschall Aug 15 '13 at 16:04
0

Jars aren't supposed to contain jars.

I would just package the EJBs into a WAR (either directly in WEB-INF/classes or as separate ejb-jars in WEB-INF/lib), put the 3rd party libs into WEB-INF/lib and call it a day. Your approach is pretty limiting. You won't be able to inject your EJBs, and you would have to use a remote lookup.

user2664820
  • 131
  • 1
  • 2
  • 7
  • Thx, for answer - It is what i want, i want a very clear line between these elements. And when i remember right, with EJB 3.1 should it still possible, but the remote lookup with direct JNDI is planned from me, for other reasons. It seems to me that a lib directory is some kind of missing thing in the ejb-jars. I still want this seperation and have to think about it how i realized it now. – user2680083 Aug 15 '13 at 08:40