我正在尝试通过Maven将Open SAML库添加到我的Grails项目中。所以pom.xml
我添加了开放的SAML依赖项:
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml</artifactId>
<version>2.5.1-1</version>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>openws</artifactId>
<version>1.4.2-1</version>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>xmltooling</artifactId>
<version>1.3.2-1</version>
</dependency>
grails run-app
和mvn install
工作正常,但是当我将构建的war文件放入tomcat 8时,我在启动时遇到以下错误:
2015-07-22 11:17:53,091 [localhost-startStop-1] ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
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:745)
Caused by: java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
... 7 more
从一个小小的研究中我发现xml-apis:xml-apis:1.4.01应该添加到我的pom文件中,以便它出现在unpackaged war的WEB-INF / lib文件夹中。因此,我将以下依赖项添加到我的pom文件中:
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
<scope>compile</scope>
</dependency>
我还检查了mvn dependency:tree -Dverbose
生成的依赖关系树,并找到了:
+- xml-apis:xml-apis:jar:1.4.01:compile
+- org.opensaml:opensaml:jar:2.5.1-1:compile
| +- (org.opensaml:openws:jar:1.4.2-1:compile - omitted for duplicate)
| +- commons-collections:commons-collections:jar:3.1:compile
| +- commons-lang:commons-lang:jar:2.1:compile
| +- velocity:velocity:jar:1.5:compile
| | +- (commons-collections:commons-collections:jar:3.1:compile - omitted for duplicate)
| | \- (commons-lang:commons-lang:jar:2.1:compile - omitted for duplicate)
| +- org.owasp.esapi:esapi:jar:2.0GA:compile
| +- (xml-apis:xml-apis:jar:1.4.01:runtime - omitted for duplicate)
| +- xerces:xercesImpl:jar:2.10.0:runtime
| | \- (xml-apis:xml-apis:jar:1.4.01:runtime - omitted for duplicate)
| +- xml-resolver:xml-resolver:jar:1.2:runtime
| \- xalan:xalan:jar:2.7.1:runtime
| \- xalan:serializer:jar:2.7.1:runtime
| \- (xml-apis:xml-apis:jar:1.3.04:runtime - omitted for conflict with 1.4.01)
+- org.opensaml:openws:jar:1.4.2-1:compile
| +- (org.opensaml:xmltooling:jar:1.3.2-1:compile - omitted for duplicate)
| +- commons-codec:commons-codec:jar:1.3:compile
| +- commons-httpclient:commons-httpclient:jar:3.1:compile
| | \- (commons-codec:commons-codec:jar:1.2:compile - omitted for conflict with 1.3)
| +- (xml-apis:xml-apis:jar:1.4.01:runtime - omitted for duplicate)
| +- (xerces:xercesImpl:jar:2.10.0:runtime - omitted for duplicate)
| +- (xml-resolver:xml-resolver:jar:1.2:runtime - omitted for duplicate)
| \- (xalan:xalan:jar:2.7.1:runtime - omitted for duplicate)
+- org.opensaml:xmltooling:jar:1.3.2-1:compile
| +- org.slf4j:slf4j-api:jar:1.6.1:compile
| +- org.slf4j:jcl-over-slf4j:jar:1.6.1:compile
| | \- (org.slf4j:slf4j-api:jar:1.6.1:compile - omitted for duplicate)
| +- org.slf4j:log4j-over-slf4j:jar:1.6.1:compile
| | \- (org.slf4j:slf4j-api:jar:1.6.1:compile - omitted for duplicate)
| +- org.slf4j:jul-to-slf4j:jar:1.6.1:compile
| | \- (org.slf4j:slf4j-api:jar:1.6.1:compile - omitted for duplicate)
| +- joda-time:joda-time:jar:2.8.1:compile
| +- org.bouncycastle:bcprov-jdk15:jar:1.45:compile
| +- org.apache.santuario:xmlsec:jar:1.4.4:compile
| +- ca.juliusdavies:not-yet-commons-ssl:jar:0.3.9:compile
| | \- (commons-httpclient:commons-httpclient:jar:3.0:compile - omitted for conflict with 3.1)
| +- net.jcip:jcip-annotations:jar:1.0:compile
| +- (xml-apis:xml-apis:jar:1.4.01:runtime - omitted for duplicate)
| +- (xerces:xercesImpl:jar:2.10.0:runtime - omitted for duplicate)
| +- (xml-resolver:xml-resolver:jar:1.2:runtime - omitted for duplicate)
| \- (xalan:xalan:jar:2.7.1:runtime - omitted for duplicate)
似乎所需的xml-apis jar将被打包到war文件中,所以在WEB-INF / lib中,但是在使用mvn install
与pom文件构建战争之后,我仍然得到了上面没有发现类错误,xml-apis jar仍未出现在WEB-INF / lib文件夹中。我想我遵循了这个问题的通常处方,但我仍然无法解决这个问题。有谁知道为什么xml-apis依赖关系没有打包到war文件中,或者为什么在Tomcat启动期间出现这个错误?感谢。
答案 0 :(得分:1)
我能够通过从POM中的所有Open SAML依赖项中排除xerces:xercesImpl jar来解决此问题。
POM中的Open SAML依赖关系如下所示:
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml</artifactId>
<version>2.5.1-1</version>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>openws</artifactId>
<version>1.4.2-1</version>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>xmltooling</artifactId>
<version>1.3.2-1</version>
<exclusions>
<exclusion>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</exclusion>
</exclusions>
</dependency>