27

I've just upgraded to NetBeans 7.1 from 7.0. On opening a JSF managed bean it "helpfully" told me that it couldn't find my beans.xml file so would I like it created for me. I knew I had a beans.xml file under WEB-INF but I said yes anyway to see what happened. A new beans.xml was created under META-INF for me.

Thinking I'd made a mistake I deleted the file under WEB-INF only to have my application fail at start up. Putting beans.xml back into WEB-INF fixed that problem. This page seems to think both locations are valid: http://seamframework.org/Documentation/WhatIsBeansxmlAndWhyDoINeedIt

So, the question is which folder should beans.xml live in WEB-INF or META-INF?

I'm running GlassFish 3.1.1 and Java 7

wobblycogs
  • 4,083
  • 7
  • 37
  • 48

1 Answers1

43

Having beans.xml placed to the WEB-INF directory is fine in your case, because most likely beans are under WEB-INF classes.

Correct place for beans.xml depends about type of archive and location of bean classes.

In specification this is explained as follows:

Bean classes of enabled beans must be deployed in bean archives.

  • A library jar, EJB jar, application client jar or rar archive is a bean archive if it has a file named beans.xml in the META-INF directory.
  • The WEB-INF/classes directory of a war is a bean archive if there is a file named beans.xml in the WEB-INF directory of the war.
  • A directory in the JVM classpath is a bean archive if it has a file named beans.xml in the META-INF directory.
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Mikko Maunu
  • 41,366
  • 10
  • 132
  • 135
  • Excellent answer thanks, taught me something new. I suspect NetBeans is wrong in this situation. – wobblycogs Feb 29 '12 at 18:57
  • The answer helped me to understand the exception `javax.enterprise.inject.UnsatisfiedResolutionException: Api type ...` exception I got using @Inject in a servlet. I had the beans.xml placed in the META-INF instead of the WEB-INF. – p1brunne Jan 07 '13 at 12:50