Reputation: 7357
As known, the JBoss AS 7.0.0
provides some apache-commons
dependencies out of the box. They are located in the
$JBOSS_HOME$\modules\org\apache\commons\lang\main
So, I tried to use these provided dependencies by declaring the following dependency in my pom.xml
:
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons.version}</version>
<scope>provided</scope>
</dependency>
And when I tried to use of of its classes I got:
java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils
com.badmitrii.EmployeeListController.getEmployees(EmployeeListController.java:39)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:483)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
Of course, if I replace the scope
tag with compile
it'll be work fine. But what's wrong with the usage of the library embedded into the server? Maybe additional configuration needed?
Upvotes: 0
Views: 476
Reputation: 3500
Try adding org.apache.commons.lang in the Dependencies section of your META-INF/MANIFEST.MF file.
I think the problem is that you are not declaring the dependency, so JBoss is not loading the class for you..
Hope it helps!
EDIT: You can set this up through maven using maven-war-plugin or maven-ear-plugin. Here's an example:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!-- Maven will append the version to the finalName (which is the name
given to the generated war, and hence the context root) -->
<warName>${project.artifactId}</warName>
<archive>
<manifestEntries>
<Dependencies>org.apache.commons.lang</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
Upvotes: 1