java - How do I import the javax.servlet API in my Eclipse project? -
i want develop servlets in eclipse, says package javax.servlet cannot resolved. how can add javax.servlet package eclipse project?
ensure you've right eclipse , server
ensure you're using @ least eclipse ide java ee developers (with ee). contains development tools create dynamic web projects , integrate servletcontainers (those tools part of web tools platform, wtp). in case had eclipse ide java (without ee), , manually installed ee related plugins, chances wasn't done properly. you'd best trash , grab real eclipse ide java ee one.
you need ensure have servletcontainer installed on machine implements @ least same servlet api version servletcontainer in production environment, example apache tomcat, oracle glassfish, jboss as/wildfly, etc. usually, downloading zip file , extracting sufficient. in case of tomcat, not download exe format, that's windows based production environments. see a.o. several ports (8005, 8080, 8009) required tomcat server @ localhost in use.
a servletcontainer concrete implementation of servlet api. note java ee sdk download @ oracle.com contains glassfish. if happen have downloaded java ee sdk, have glassfish. note example glassfish , jboss as/wildfly more servletcontainer, supports jsf, ejb, jpa , other java ee fanciness. see a.o. what java ee?
integrate server in eclipse , associate project
once having installed both eclipse java ee , servletcontainer on machine, following steps in eclipse:
integrate servletcontainer in eclipse
a. via servers view
- open servers view in bottom box.
- rightclick there , choose new > server.
pick appropriate servletcontainer make , version , walk through wizard.
b. or, via eclipse preferences
associate server project
a. in new project
- open project navigator/explorer on left hand side.
- rightclick there , choose new > project , in menu web > dynamic web project.
in wizard, set target runtime integrated server.
b. or, in existing project
either way, eclipse automatically take servletcontainer's libraries in build path. way you'll able import , use servlet api.
never carry around loose server-specific jar files
you should in case not have need fiddle around in build path property of project. should above never manually copy/download/move/include individual servletcontainer-specific libraries servlet-api.jar, jsp-api.jar, el-api.jar, j2ee.jar, javaee.jar, etc. lead future portability, compatibility, classpath , maintainability troubles, because webapp not work when it's deployed servletcontainer of different make/version libraries obtained from.
in case you're using maven, need make absolutely sure servletcontainer-specific libraries provided target runtime marked <scope>provided</scope>.
here typical exceptions can when litter /web-inf/lib or /jre/lib, /jre/lib/ext, etc servletcontainer-specific libraries in careless attempt fix compilation errors:
- java.lang.nullpointerexception @ org.apache.jsp.index_jsp._jspinit
- java.lang.noclassdeffounderror: javax/el/elresolver
- java.lang.nosuchfielderror: is_dir
- java.lang.nosuchmethoderror: javax.servlet.jsp.pagecontext.getelcontext()ljavax/el/elcontext;
- java.lang.abstractmethoderror: javax.servlet.jsp.jspfactory.getjspapplicationcontext(ljavax/servlet/servletcontext;)ljavax/servlet/jsp/jspapplicationcontext;
- org.apache.jasper.jasperexception: method getjspapplicationcontext(servletcontext) undefined type jspfactory
- java.lang.verifyerror: (class: org/apache/jasper/runtime/jspapplicationcontextimpl, method: createelresolver signature: ()ljavax/el/elresolver;) incompatible argument function
- jar not loaded. see servlet spec 2.3, section 9.7.2. offending class: javax/servlet/servlet.class




Comments
Post a Comment