java - Attempting to access web.xml getting NoInitialContextException -
i building web application class (yes homework assignment). using eclipse , tomcat 8. have following code service factory:
package com.orderonline.model.service.factory; import javax.naming.context; import javax.naming.initialcontext; import com.orderonline.model.service.interfaces.iservice; public class servicefactory { public iservice getservice(string name) throws exception { try { class<?> newclass = class.forname(getimplname(name)); return (iservice)newclass.newinstance(); } catch(exception e) { throw new exception(name); } } private string getimplname(string name) throws exception { context initctx = new initialcontext(); context envctx = (context) initctx.lookup("java:comp/env"); string lookupclass = (string) envctx.lookup(name); return lookupclass; } }
i expected in web.xml file located @ orderonline/webcontent/web-inf/web.xml following:
<env-entry> <env-entry-name>iusersvc</env-entry-name> <env-entry-type>java.lang.string</env-entry-type> <env-entry-value>com.orderonline.model.service.interfaces.iusersvc</env-entry-value> </env-entry>
instead getting exception thrown when line run:
context envctx = (context) initctx.lookup("java:comp/env");
the exception is:
javax.naming.noinitialcontextexception: need specify class name in environment or system property, or applet parameter, or in application resource file: java.naming.factory.initial
i new @ this, missing important peice of information me, , more happy provide more information needed. appreciate assistance can provided me read env-entry-value web.xml file.
you need initial context factory stated in this answer on so.
system.setproperty(context.initial_context_factory, "org.apache.naming.java.javaurlcontextfactory");
Comments
Post a Comment