我有一个带有这些依赖项的maven(m2e eclipse)项目:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml-core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml-messaging-api</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml-profile-api</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml-saml-api</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml-security-api</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml-soap-api</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml-storage-api</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml-xmlsec-api</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml-saml-impl</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.opensaml</groupId>
<artifactId>xmltooling</artifactId>
<version>1.4.6</version>
</dependency>
</dependencies>
在Eclipse中运行mvn install -U
,一切正常。
OLD
.............................
所以我使用Maven Dependency Plugin从依赖项中提取所有jar并在另一个项目中使用它们。
在本项目中,当我输入:
InitializationService.initialize();
我成了这个错误:
Exception in thread "main" java.lang.ClassCastException: org.opensaml.xml.signature.impl.CryptoBinaryBuilder cannot be cast to org.opensaml.core.xml.XMLObjectBuilder
at org.opensaml.core.xml.config.XMLConfigurator.initializeObjectProviders(XMLConfigurator.java:238)
at org.opensaml.core.xml.config.XMLConfigurator.load(XMLConfigurator.java:203)
at org.opensaml.core.xml.config.XMLConfigurator.load(XMLConfigurator.java:188)
at org.opensaml.core.xml.config.XMLConfigurator.load(XMLConfigurator.java:162)
at org.opensaml.core.xml.config.AbstractXMLObjectProviderInitializer.init(AbstractXMLObjectProviderInitializer.java:52)
at org.opensaml.core.config.InitializationService.initialize(InitializationService.java:56)
更新:我可以通过删除完整的maven存储库
来解决此问题 更新
................................
然后我使用Maven Assembly Plugin生成一个包含所有依赖项的jar。我可以传递InitializationService.initialize()
罚款,但我在:
marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(authnRequest.getElementQName());
Null从工厂返回。
相关:OpenSAML 3 unmarshaller is null
为什么我的程序在maven测试中运行时有效,但在我使用jar或带有dependend库的代码时却没有?