2

i'm currently learning spring ioc/struts2, and i keep getting a NoClassDefFoundError. the correct jars are in my pom file, so i am befuddled. following this advice, i added the problematic jar to my bootstrap entries, and it got rid of that particular NoClassDefFoundError, but i was met with another one.

i keep adding jars to my bootstrap entries, and that seems to fix each problem that comes up, but i want to make sure i'm actually solving my problem and not just putting a bandaid on it.

here are the current bootstrap entries:

bootstrap entries

below are my pom and my most recent stacktrace.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>final-project1.3.1</groupId>
    <artifactId>final-project1.3.1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>final-project1.3.1</name>
    <description>final-project1.3.1</description>
    <dependencies>
        <!-- hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.0.Final</version>
        </dependency>
        <dependency>
            <groupId>antlr</groupId>
            <artifactId>antlr</artifactId>
            <version>2.7.7</version>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.common</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>4.0.4.Final</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.18.1-GA</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.1.4.GA</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.logmanager</groupId>
            <artifactId>jboss-logmanager</artifactId>
            <version>1.5.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging-annotations</artifactId>
            <version>1.2.0.Beta1</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.transaction</groupId>
            <artifactId>jboss-transaction-api_1.2_spec</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss</groupId>
            <artifactId>jandex</artifactId>
            <version>1.1.0.Final</version>
        </dependency>
        <!-- end hibernate -->
        <!-- start spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>3.2.3.RELEASE</version>
        </dependency>
        <!-- end spring -->

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>2.3.14.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-junit-plugin</artifactId>
            <version>2.3.14.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-spring-plugin</artifactId>
            <version>2.3.14.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-tiles-plugin</artifactId>
            <version>2.3.14.3</version>
        </dependency>

        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-api</artifactId>
            <version>2.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-core</artifactId>
            <version>2.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-jsp</artifactId>
            <version>2.0.6</version>
        </dependency>
        <!-- start spring -->
        <!-- struts -->
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.8.3</version>
        </dependency>
        <dependency>
            <groupId>commons-chain</groupId>
            <artifactId>commons-chain</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.1</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-digester</groupId>
            <artifactId>commons-digester</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>commons-el</groupId>
            <artifactId>commons-el</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.3</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging-api</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>1.6</version>
        </dependency>
        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.19</version>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>ognl</groupId>
            <artifactId>ognl</artifactId>
            <version>3.0.6</version>
        </dependency>
        <dependency>
            <groupId>oro</groupId>
            <artifactId>oro</artifactId>
            <version>2.0.8</version>
        </dependency>
        <!-- end struts -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>
    </dependencies>
    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

and the stack trace:

 Jan 12, 2014 6:23:09 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/carriecoxwell/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Jan 12, 2014 6:23:09 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:final-project1.3.1' did not find a matching property.
Jan 12, 2014 6:23:10 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jan 12, 2014 6:23:10 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jan 12, 2014 6:23:10 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1304 ms
Jan 12, 2014 6:23:10 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 12, 2014 6:23:10 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.40
Jan 12, 2014 6:23:10 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [300] milliseconds.
Jan 12, 2014 6:23:11 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: org/springframework/beans/factory/ListableBeanFactory
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
    at java.lang.Class.getConstructor0(Class.java:2803)
    at java.lang.Class.newInstance(Class.java:345)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:138)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4823)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

Jan 12, 2014 6:23:11 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
Jan 12, 2014 6:23:11 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Jan 12, 2014 6:23:11 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/final-project1.3.1] startup failed due to previous errors
Jan 12, 2014 6:23:11 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jan 12, 2014 6:23:11 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jan 12, 2014 6:23:11 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1109 ms

thanks in advance.

DB5
  • 13,553
  • 7
  • 66
  • 71
  • Which class can't be found? – Sotirios Delimanolis Jan 12 '14 at 23:44
  • org/springframework/beans/factory/ListableBeanFactory or something it needs. – bmargulies Jan 12 '14 at 23:48
  • currently it's ListableBeanFactory. -- whoops, @bmargulies, i didn't see your reply before i responded. – thatpaintingelephant Jan 12 '14 at 23:51
  • 1
    These things are very hard to diagnose, because they can result from a class needed by the class named, such as a type in an exception signature or a static field. – bmargulies Jan 12 '14 at 23:53
  • @bmargulies it seems that way! i'm happy to keep adding jars to the bootstrap entries. i just wanted to check in here and make sure there wasn't something in the big picture that i was missing. – thatpaintingelephant Jan 12 '14 at 23:59
  • 1
    hmm. 'mvn dependency:tree' and see if there is funny-business under spring? – bmargulies Jan 13 '14 at 00:01
  • that's a new trick for me! i ran it, but i'm not quite sure what i should be looking for. here is what it says for spring: – thatpaintingelephant Jan 13 '14 at 00:08
  • `[INFO] +- org.springframework:spring-aop:jar:3.2.3.RELEASE:compile [INFO] | \- aopalliance:aopalliance:jar:1.0:compile [INFO] +- org.springframework:spring-beans:jar:3.2.3.RELEASE:compile [INFO] +- org.springframework:spring-context:jar:3.2.3.RELEASE:compile [INFO] +- org.springframework:spring-core:jar:3.2.3.RELEASE:compile [INFO] +- org.springframework:spring-expression:jar:3.2.3.RELEASE:compile [INFO] +- org.springframework:spring-test:jar:3.2.3.RELEASE:compile [INFO] +- org.springframework:spring-web:jar:3.2.3.RELEASE:compile ` – thatpaintingelephant Jan 13 '14 at 00:08
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/45073/discussion-between-thatpaintingelephant-and-bmargulies) – thatpaintingelephant Jan 13 '14 at 00:21
  • also, if someone could offer insight into why this question has been downvoted, i'd appreciate it. – thatpaintingelephant Jan 13 '14 at 00:22

2 Answers2

3

java.lang.NoClassDefFoundError means the runtime version of the class in the classpath is not the same as that at compile time.

Your stacktrace does not have the ClassNotFoundError - so your problem could be multiple versions of the class being found when the server is deploying. ListableBeanFactory is part of spring-beans.jar

Can you search for how many versions of the spring-beans.jar are found in the run time server environment i.e. within Tomcat as part of the boorstrap you added and also within your own webapp libraries under WEB-INF?
May be there are multiples or the versions are clashing with each other.

Also looks like you're running Tomcat within your IDE in which case you'll have to search in the right location.

JoseK
  • 31,141
  • 14
  • 104
  • 131
  • i searched my project, and 3.2.3.RELEASE is the only version that shows up. i don't have anything in my webapp libraries. should i be putting my spring jars there instead of in my POM? – thatpaintingelephant Jan 13 '14 at 13:21
  • For the webapp to run, yes its preferred to put the Spring jars there. This is autonatically taken from your POM, but whats surprising to me is your mvn dependencytree shows `org.springframework:spring-beans:jar:3.2.3.RELEASE:compile` which means it's only used for the Compile and not bundled into the Web app which is the default. But your POM does not specify a `scope` of `compile` so why does mvn only take it for compile time. – JoseK Jan 14 '14 at 05:48
  • Can you search for any other pom.xml files which might be over-riding this one which you've pasted. Maven is definitely getting the `compile` scope defined for all your Spring jars which is not needed. Your Spring jars will then go into the WEB-INF/lib of your webapp. – JoseK Jan 14 '14 at 05:51
  • i had a pom file in another project that used the compile scope, and as soon as i deleted that project, it solved my problem. i don't quite understand why that is the case, but i'm glad it's working! – thatpaintingelephant Jan 14 '14 at 12:49
0
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.3.RELEASE</version>
</dependency>

you seems to be missing spring-beans from this question of stackoverflow.

Community
  • 1
  • 1
Ashish
  • 735
  • 1
  • 6
  • 15