众所周知,JBoss AS 7.0.0
提供了一些开箱即用的apache-commons
依赖项。它们位于
$JBOSS_HOME$\modules\org\apache\commons\lang\main
所以,我尝试通过在pom.xml
中声明以下依赖项来使用这些提供的依赖项:
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>${commons.version}</version>
<scope>provided</scope>
</dependency>
当我尝试使用它的类时,我得到了:
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)
当然,如果我将scope
标记替换为compile
,它就可以正常工作。但是使用嵌入服务器的库有什么问题?可能还需要其他配置吗?
答案 0 :(得分:1)
尝试在META-INF / MANIFEST.MF文件的Dependencies部分添加org.apache.commons.lang。
我认为问题是你没有声明依赖,所以JBoss没有为你加载这个类..
希望它有所帮助!
编辑:你可以使用maven-war-plugin或maven-ear-plugin通过maven设置它。这是一个例子:
<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>