java.lang.ClassNotFoundException: org.apache.commons.lang.xwork.StringUtils

Question:

I am facing a strange problem.

It was necessary to raise the Struts version from 2.2.1 to 2.3.x

After that, the following errors appeared:

[10/11/2016 05:01:28 PM] WARN  log - Failed startup of context WebAppContext@4593aeea@4593aeea/,file:/C:/project/web/
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException - Class: com.opensymphony.xwork2.inject.ContainerBuilder$4
File: ContainerBuilder.java
Method: create
Line: 132 - com/opensymphony/xwork2/inject/ContainerBuilder.java:132:-1
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:483)
    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
    at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:74)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:668)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:204)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:994)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:588)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:380)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:92)
    at org.eclipse.jetty.server.Server.doStart(Server.java:242)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at com.kpclabs.test.ProcessingPortalWebRunner.main(ProcessingPortalWebRunner.java:28)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:132)
    at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)
    at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:514)
    at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:524)
    at com.opensymphony.xwork2.inject.ContainerImpl$9.call(ContainerImpl.java:555)
    at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:584)
    at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:553)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:232)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:68)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:429)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:471)
    ... 14 more
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:502)
    at com.opensymphony.xwork2.inject.ContainerImpl$7.call(ContainerImpl.java:539)
    at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:593)
    at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:537)
    at com.opensymphony.xwork2.config.impl.LocatableFactory.create(LocatableFactory.java:32)
    at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:130)
    ... 24 more
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.construct(ContainerImpl.java:447)
    at com.opensymphony.xwork2.inject.ContainerImpl.inject(ContainerImpl.java:499)
    ... 29 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.construct(ContainerImpl.java:426)
    ... 30 more
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang/xwork/StringUtils
    at org.apache.struts2.spring.StrutsSpringObjectFactory.<init>(StrutsSpringObjectFactory.java:104)
    ... 35 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.xwork.StringUtils
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

pom.xml :

<dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>${struts2.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-json-plugin</artifactId>
            <version>${struts2.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.struts</groupId>
                    <artifactId>struts2-junit-plugin</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-junit-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>  
        <dependency>
            <groupId>org.apache.struts.xwork</groupId>
            <artifactId>xwork-core</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-tiles-plugin</artifactId>
            <version>${struts2.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

    

Well

<struts2.version>2.3.7</struts2.version>

I just can't decide. Can anyone suggest a direction?

Answer:

Error

Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.xwork.StringUtils

There is a version conflict somewhere. That is, libraries appear on the classpath that should not be there after building the application.

If earlier the StringUtils utility from the xwork library was used, then in new versions they began to use utilities from the org.apache.commons.lang package, which is located in another library.

By the way, in the latest versions, you no longer need to specify the dependency on xwork, which is fully integrated with struts2-core.

Scroll to Top