jsf - How to install and use CDI on Tomcat? -
jsf - How to install and use CDI on Tomcat? -
i'm creating first project java ee 7, i'm having trouble. appreciate help.
tomcat 7.0.34 jsf 2.2 primefaces 3.5 javaee-api-7.0.jarwhen application start, tomcat log shows next message:
"validatejarfile (c:\...\build\web\web-inf\lib\javaee-api-7.0.jar)-jar not loaded. see servlet 2.3 spec, section 9.7.2. offending class: javax/servlet/servlet .class" when click on button calls managed bean, error:
advertĂȘncia: /index.xhtml @18,66 value="#{indexmb.user}": target unreachable, identifier 'indexmb' resolved null javax.el.propertynotfoundexception: /index.xhtml @18,66 value="#{indexmb.user}": target unreachable, identifier 'indexmb' resolved null indexmb
@named("indexmb") @requestscoped public class indexmb { private string password; private string user; public string logintest(){ homecoming (this.user.equals("admin") ? "adminpage" : "inoutpage"); } // getters , setters } index.xhtml
<html ...> <f:loadbundle basename="i18n" var="bundle" /> <h:head> <title>#{bundle['index_title']}</title> </h:head> <h:body> #{bundle['index_appname']} <br /> <h:form id="frmindex"> <p:panelgrid columns="2"> <p:outputlabel for="user" value="#{bundle['lbluser']}" /> <p:inputtext id="user" value="#{indexmb.user}" /> <p:outputlabel for="password" value="#{bundle['lblpassword']}" /> <p:password id="password" value="#{indexmb.password}" /> </p:panelgrid> <p:commandbutton action="#{indexmb.logintest}" value="#{bundle['btn_login']}" /> </h:form> </h:body> faces-config.xml
<?xml version='1.0' encoding='utf-8'?> <faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"> <application> <locale-config> <default-locale>pt_br</default-locale> <supported-locale>en</supported-locale> <supported-locale>fr</supported-locale> </locale-config> </application> these topics have not helped me:
java ee 6 @javax.annotation.managedbean vs. @javax.inject.named vs. @javax.faces.managedbean target unreachable identifier resolved null target unreachable, identifier resolved null javax.el.propertynotfoundexception : target unreachable, identifier 'login' resolved null spring + jsf http://www.andrejkoelewijn.com/blog/2010/03/05/jee-cdi-tip-target-unreachable-identifier-resolved-to-null/
tomcat beingness barebones jsp/servlet container doesn't back upwards cdi out box. how did install cdi? did drop javaee-api-7.0.jar in /web-inf/lib code compile? oh please no, not right way. java ee api jar contains solely api classes, not concrete implementation. rid of whole jar. can cause many other portability troubles ones described in answer: how import javax.servlet api in eclipse project? should installing concrete implementation along specific api.
you have 2 options:
drop tomcat , go true java ee container. you're using tomcat, step on tomee. it's simple, download tomee web profile zip file, extract , integrate in eclipse same way did tomcat. don't forget remove java ee jar file webapp , alter targeted runtime property in project's properties tomcat tomee java ee dependencies resolved.
no additional jars or configuration necessary. can remove jsf jars webapp. tomee beingness true java ee container provides jsf out box.
install true cdi implementation on tomcat. weld 1 of available cdi implementations. in the weld installation guide can find instructions how integrate in tomcat. sake of completeness , future reference, here steps:
drop weld-servlet.jar in webapp's /web-inf/lib. in case you're using maven, utilize this coordinate:
<dependency> <groupid>org.jboss.weld.servlet</groupid> <artifactid>weld-servlet</artifactid> <version>2.3.2.final</version> </dependency> create /meta-inf/context.xml file in webapp next content:
<context> <resource name="beanmanager" auth="container" type="javax.enterprise.inject.spi.beanmanager" factory="org.jboss.weld.resources.managerobjectfactory"/> </context> create empty /web-inf/beans.xml file in webapp.
that's (note: in older weld servlet versions, you'd need explicitly register cdi bean manager , weld listener in web.xml too, that's unnecessary current versions).
unrelated concrete problem, jsp/servlet apis of tomcat 7 not comply apis of java ee 7, instead complies java ee 6 (servlet 3.0 / jsp 2.2). if want tomcat equivalent of java ee 7 (servlet 3.1 / jsp 2.3), should looking @ tomcat 8. see apache tomcat version matrix.
jsf tomcat cdi jsf-2.2
Comments
Post a Comment