Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build path is incomplete. Cannot find class file for javax/servlet/ServletContext

very new to java. Working on a CRUD hibernate spring project (sts). When configuring the xml file i get the error "Build path is incomplete.Cannot find class file for javax/servlet/ServletContext", by thebean id="viewResolver". How do I put this on the build path. cheers.

<context:annotation-config />
<context:component-scan base-package="com.ger" />   


<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
    p:location="/WEB-INF/jdbc.properties" />

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
    p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" />
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation">
        <value>classpath:hibernate.cfg.xml</value>
    </property>
    <property name="configurationClass">
        <value>org.hibernate.cfg.AnnotationConfiguration</value>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${jdbc.dialect}</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property> 
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean> 

like image 416
flutter Avatar asked May 16 '13 01:05

flutter


3 Answers

Application seems to be missing one of the jars from servlet-api.jar, jsp-api.jar, el-api.jar, j2ee.jar, javaee.jar. And you don't need to copy and paste these into classpath. When application gets deployed on server, you will get those. You should above all never manually copy/download/move/include the individual servletcontainer-specific libraries.

If you are running this project from IDE, Check your server configurations.

like image 132
Jeevan Patil Avatar answered Nov 11 '22 05:11

Jeevan Patil


The problem is that the JIT in Eclipse does not work the same as the Java JDK that you can use on the command line with something like Maven. To fix this, just add the following to your pom.xml file.

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
like image 33
Joshua Wilson Avatar answered Nov 11 '22 06:11

Joshua Wilson


  • Windows 8.1, Maven 3.2.3
  • Spring STS 3.6.3.SR1
  • Maven Integration for Eclipse m2e 1.5.1.20150109
  • Spring IDE plugin 3.6.3.201411271034-RELEASE etc.

Had similar problem for several days. It said that some classes were missing from a dependent project (but they were present) that was opened and it was a Spring AOP plugin (?) problem. When closing the project, the dependency is seen correctly in the Maven repository. The problem is not observed when doing maven builds from the command line, only in STS.

I tried various things. One of them, that it seem to work, is to open the applicationcontext.xml file with Spring Config Editor, go to the Namespaces tab, unselect the context namespace, save (maybe do some cleanup), then select the context namespace, save again. Praying or dancing your favorite rain dance should help also :) The line where I saw this error was:

<context:component-scan base-package="aaa.bbb" />
like image 4
razvanone Avatar answered Nov 11 '22 07:11

razvanone