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
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.
Related
I am using JBOSS 7
In my custom jar I am implementing an Interface. The interface is in a jar packaged with ECM.ear file. Unless I put my custom jar inside the web-inf/lib folder (of the war file located in ear file) I am getting ClassNotFoundException w.r.to the interface.
I created a module for my custom jar but I don't how to set up a dependency with ear file. I copied the jar containing the interface say mdm.jar and placed it in the module and also added an entry in the resource root of module.xml. After restarting I am getting ClassNotFoundException for the classes referred by mdm.jar, which arein ear file.
How to achieve this dependency?
Thanks,
Raghu
JBOSS 7 needs you to place the packaged jar files in the lib folders of your web-inf/lib or the ear/lib cos of the Class Loading Precedence that JBOSS server follows.
Alternatively you could load it as a module, but you need to specify any addition of this kind outside of JBOSS default supplied modules using your MANIFEST file or jboss-deployment-structure.xml
This link should provide you more insight on what would suit you best.
Hope it helps.
I'm using JBoss Developer Studio 7 (alpha) and have an EAR project with two WARs and one JAR. The JAR is a JPA project. The JAR contains all JPA Entities and also persistance.xml (inside META-INF folder). So I'd like to use the persitence unit defined in the JAR from both WARs. Since the idea is that each WAR has to use the shared persistance.xml from the JAR (JPA project) y removed the persitence.xml in each WAR MATA-INF folder, but then when I want to build the WAR I get "No persistence.xml file found in project (WAR name)".
How I resolve this? If I set some dummy configuration in the WAR persistance.xml the IDE let me buid withot errors, but I don't like this, I have two persitence units that never will be used.
**EntityManagerFactory factory=Persistence.getEnityManagerFactory(???);**
In specification they are explained in the context of EJBs.But i am not understanding the actual possible locations of persistence.xml in a web archive.
The persistence.xml must always be in the META-INF directory on the classpath. Normally it will be inside a jar that is on the classpath, such as a jar in /WEB-INF/lib/ in your war file.
I have the log4j.properties and another .properties file under src and it works deployed in gwt dev mode. To build the war to launch to tomcat I use an ant script that compiles the .java classes and puts them in a JAR file. The JAR file gets copied into the WEB-INF folder in the war file.
The app runs fine when I don't use log4j but it can't find the properties file when I attempt to use log4j. All of the answers I see say WEB-INF/classes, but my project doesn't have a WEB-INF/classes directory, instead the JAR file that was copied to WEB-INF contains my projects classes.
You have to put log4j.properties (or log4j.xml) file into directory or JAR that is considered by your servlet-container as resource in Classpath.
So, simply create WEB-INF/classes directory and put it there, or pack it into your JAR.
See also Where should I put the log4j.properties file? - it could be useful.
This one is beating me, and I have not been able to figure it out ... So here it goes.
I want to add a Message Drive Bean to my app which is packaged as a .ear file
Following the documentation I've created a jboss.xml and a ejb-jar.xml, which I tried to put on the META-INF and the root and on the WEB-INF but I just don;t see it working (i.e. the MDB is never loaded, nor it received the messages.
My ear file looks like:
META-INF/
META-INF/MANIFEST.MF
META-INF/application.xml
myapp.war
My final solution was to separate the MDB code (and supporting classes) into a separate file inside the ear (myapp-mdb.jar) And to support that with the same hibernate mappings and classes, the hibernate related files were packaged on the myapp.har.
META-INF\MANIFEST.MF
META-INF\application.xml
META-INF\jboss-app.xml
myapp-mdb.jar
myapp.har
myapp.war
Just posting the answer for reference.