0

Added snap of jar i added

This is error im getting

i have added all jars from maven. My POM looks like below (Sorry cant post pom with header as i dont have enough reputation to post links):

<properties>
    <org.springframework.version>4.0.6.RELEASE</org.springframework.version>
    <jdk.version>1.7</jdk.version>
</properties>

<dependencies>
    <!-- Core utilities used by other modules. Define this if you use Spring 
        Utility APIs (org.springframework.core.*/org.springframework.util.*) -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework.version}</version>
        <scope>provided</scope>
    </dependency>

    <!-- Expression Language (depends on spring-core) Define this if you use 
        Spring Expression APIs (org.springframework.expression.*) -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Bean Factory and JavaBeans utilities (depends on spring-core) Define 
        this if you use Spring Bean APIs (org.springframework.beans.*) -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Aspect Oriented Programming (AOP) Framework (depends on spring-core, 
        spring-beans) Define this if you use Spring AOP APIs (org.springframework.aop.*) -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Application Context (depends on spring-core, spring-expression, spring-aop, 
        spring-beans) This is the central artifact for Spring's Dependency Injection 
        Container and is generally always defined -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Various Application Context utilities, including EhCache, JavaMail, 
        Quartz, and Freemarker integration Define this if you need any of these integrations -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Transaction Management Abstraction (depends on spring-core, spring-beans, 
        spring-aop, spring-context) Define this if you use Spring Transactions or 
        DAO Exception Hierarchy (org.springframework.transaction.*/org.springframework.dao.*) -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- JDBC Data Access Library (depends on spring-core, spring-beans, spring-context, 
        spring-tx) Define this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*) -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Object-to-Relation-Mapping (ORM) integration with Hibernate, JPA, 
        and iBatis. (depends on spring-core, spring-beans, spring-context, spring-tx) 
        Define this if you need ORM (org.springframework.orm.*) -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Object-to-XML Mapping (OXM) abstraction and integration with JAXB, 
        JiBX, Castor, XStream, and XML Beans. (depends on spring-core, spring-beans, 
        spring-context) Define this if you need OXM (org.springframework.oxm.*) -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-oxm</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Web application development utilities applicable to both Servlet and 
        Portlet Environments (depends on spring-core, spring-beans, spring-context) 
        Define this if you use Spring MVC, or wish to use Struts, JSF, or another 
        web framework with Spring (org.springframework.web.*) -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Spring MVC for Servlet Environments (depends on spring-core, spring-beans, 
        spring-context, spring-web) Define this if you use Spring MVC with a Servlet 
        Container such as Apache Tomcat (org.springframework.web.servlet.*) -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Spring MVC for Portlet Environments (depends on spring-core, spring-beans, 
        spring-context, spring-web) Define this if you use Spring MVC with a Portlet 
        Container (org.springframework.web.portlet.*) -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc-portlet</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>

    <!-- Support for Spring security Define this if you use Spring Security 
        to secure your web application -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>3.2.4.RELEASE</version>
        <scope>provided</scope>
    </dependency>

    <!-- Support for testing Spring applications with tools such as JUnit and 
        TestNG This artifact is generally always defined with a 'test' scope for 
        the integration testing framework and unit testing stubs -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${org.springframework.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.6.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.1.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.common</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>4.0.4.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.6.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>4.3.6.Final</version>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.1.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.4</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.logging</groupId>
        <artifactId>jboss-logging</artifactId>
        <version>3.1.0.CR2</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.4</version>
    </dependency>

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.7</version>
    </dependency>

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.7</version>
    </dependency>

    <!-- <dependency> <groupId>javax.el</groupId> <artifactId>javax.el-api</artifactId> 
        <version>3.0.0</version> </dependency> -->



    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.3-1100-jdbc4</version>
    </dependency>


    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>


</dependencies>

What could be the cause of error? Is spring not able to add classpath resource anymore?

Raj
  • 45
  • 1
  • 9
  • 1
    Could you do a `mvn dependency:tree` instead ? This command will print the dependencies you are using and not a very restricted view of your dependencies. – NoDataFound Jul 26 '14 at 18:43
  • You have problems with your dependencies... [check answer](http://stackoverflow.com/questions/24842455/formselect-unable-to-retrieve-data-from-database/24910948#24910948) to a different problem, but probably with the same underlying issue (multiple spring version). – Pavel Horal Jul 26 '14 at 18:43
  • im unable to find if there is any mismatch with the versions required by spring – Raj Jul 26 '14 at 19:09
  • Dependencies look fine, indeed. Is the stack trace from running some Maven task? Which task are you running? `tomcat7:run`? – Pavel Horal Jul 26 '14 at 19:12
  • Yup.I ran tomcat to start my spring-mvc app, but it failed throwing the stack trace that it is unable to load hibernate-persistence from classpath. This is in my spring-servlet.xml – Raj Jul 26 '14 at 19:15
  • Can you try to run `mvn clean` (just to be sure the problem you are facing is not a trivial build inconsistency). – Pavel Horal Jul 26 '14 at 19:19
  • i tried running mvn clean but no gain, the same issue – Raj Jul 26 '14 at 19:32
  • Ah... how could I have missed that. Your `spring-core` dependency is marked as `provided` (as well as spring-security). Such JARs are not packaged together with the web application => `NoClassDefFoundError` if you don't have tham on shared class loader location (which does not even make sense when running embedded Tomcat). – Pavel Horal Jul 26 '14 at 19:35
  • Thanks man! you rock! it is working now, I was definitely on moon when writing such weired code. – Raj Jul 26 '14 at 19:53
  • Added my comment as a proper answer so you can accept it. Thank you. – Pavel Horal Jul 26 '14 at 20:40

1 Answers1

0

Your spring-core dependency is marked as provided (as well as spring-security-core). Such dependencies are not packaged together with the web application and it might lead to NoClassDefFoundError / ClassNotFoundException if you don't have them on shared / server class loader path (which does not even make sense when running embedded Tomcat).

Removing the provided flag should fix your issue.

Pavel Horal
  • 17,782
  • 3
  • 65
  • 89