Search code examples
javajsf-2ejb-3.0java-ee-6

how to use managed Bean in another project in the same Java EE application


i have a question if it´s possible to use a ManagedBean of project web X in another project web Y that both are in the same Enterprise application?

Any help would be appreciated Thanks.


Solution

  • Just create a Jar which goes into your final Java EE application (referenced by both of the projects if you're using Maven). Then, add the simplest faces configuration file in your Jar's META-INF directory:

    <?xml version="1.0" encoding="UTF-8"?>
    <faces-config
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
        version="2.0">
    </faces-config>
    

    That will make JSF scan this Jar's content. After that, just use annotations in the classes you want them to be managed beans:

    @ManagedBean
    @SessionScoped
    public class SessionScopedBean{
    
    ....
    
    }
    

    That's all, for more info you can visit this link.