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:

  1. 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.

      enter image description here

    b. or, via eclipse preferences

    • open window > preferences > server > runtime environments.
    • you can add, edit , remove servers here.

      enter image description here

  2. 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.

      enter image description here

    b. or, in existing project

    • rightclick project , choose properties.
    • in targeted runtimes section, select integrated server.

      enter image description here

    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:


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

ios - How can i populate the right swreveal view controller with an array of prototype cells created in main.storyboard -