0

I have a war project A that I am deploying to JBoss AS7 that uses CDI and all works fine. But I want to use some classes in another project B, which I added to my pom.xml and turned on workspace resolution for, because these classes will be shared by multiple war projects.

Now these classes work perfectly fine as long as they are in the war project A, but when I move them to B, the CDI on them stops working. The other project B has a webapp/WEB-INF/beans.xml, but when looking at the deployed war of A, project B is represented as a jar containing only class files, no beans.xml. CDI will not work, no matter what I try.

The only solution to get the beans.xml included in B is to set Bs packaging to war, at which point it isn't packaged, but deployed as a directory (named like a jar), which makes JBoss crash, and which includes all the libraries A and B use a second time.

I'm a bit lost - am I really restricted to using a single monster project if I want to use CDI in this situation ?

Torque
  • 3,319
  • 2
  • 27
  • 39
  • In order to use B as a jar and make your main war notice about that, you must put the configuration files into project's classpath, it means META-INF folder. – Aritz Feb 23 '13 at 01:05
  • Like I wrote, I already use B as a jar. That's not the problem, the problem is that CDI doesn't work on classes imported from a jar that doesn't have beans.xml, and that I can't get it to export with the beans.xml – Torque Feb 23 '13 at 01:09
  • Put your beans.xml file into */src/main/resources* folder. Then build it as a jar. – Aritz Feb 23 '13 at 01:11
  • The beans.xml file should not be in your WEB-INF folder, especially for JAR deployments. It should be in META-INF. – Perception Feb 23 '13 at 01:32
  • It turns out my continual problems stem from a different issue with JAX-RS, so I would like to accept your answer, @Xtreme Biker, if you repost it as one, since that's what solved my question here. – Torque Feb 23 '13 at 14:18

1 Answers1

1

Your problem is you are following the war project structure into a jar project, so your configuration file is not ending up into your final project's classpath. In order to solve that, move it to /src/main/resources directory and Maven will manage to reallocate it when your built is done. Take a look to the Maven standard layout explanation.

Aritz
  • 30,971
  • 16
  • 136
  • 217