如何在mule中解决java.lang.ClassNotFoundException:com.sap.conn.jco.JCoException错误?

时间:2017-10-06 11:25:54

标签: mule sap jco

我在我的项目中使用sap组件。

请在下面找到我的SAP组件示例代码:

 <sap:connector name="SAP_Configuration" jcoAsHost="${sapbw.host}" jcoUser="${sapbw.user}" jcoPasswd="${sapbw.password}" jcoSysnr="${sapbw.instance}" jcoClient="${sapbw.client}" jcoLang="${sapbw.language}" validateConnections="true" doc:name="SAP"/>

我在构建路径中添加了必需的sapidoc3和sapjco3 jar文件。由于我在窗口操作系统上工作,包括sapjco3.dll文件仍然在下面错误。

ERROR 2017-10-06 16:32:32,849 [main] org.mule.module.launcher.DefaultArchiveDeployer: 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Failed to deploy artifact 'nol-integration-v1.1', see    +
+ below                                                    +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
org.mule.module.launcher.DeploymentException: Failed to deploy artifact [nol-integration-v1.1]
    at org.mule.module.launcher.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:38) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.DefaultArchiveDeployer.guardedDeploy(DefaultArchiveDeployer.java:310) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployArtifact(DefaultArchiveDeployer.java:330) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:155) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:256) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.DefaultArchiveDeployer.deployPackagedArtifact(DefaultArchiveDeployer.java:78) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.DeploymentDirectoryWatcher.deployPackedApps(DeploymentDirectoryWatcher.java:275) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.DeploymentDirectoryWatcher.start(DeploymentDirectoryWatcher.java:150) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.MuleDeploymentService.start(MuleDeploymentService.java:100) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.MuleContainer.start(MuleContainer.java:170) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.tooling.server.application.ApplicationDeployer.main(ApplicationDeployer.java:15) ~[tooling-support-3.7.0.jar:?]
Caused by: java.lang.NoClassDefFoundError: com/sap/conn/jco/JCoException
    at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:1.8.0_121]
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[?:1.8.0_121]
    at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[?:1.8.0_121]
    at org.springframework.core.type.StandardAnnotationMetadata.hasAnnotatedMethods(StandardAnnotationMetadata.java:129) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassUtils.isLiteConfigurationCandidate(ConfigurationClassUtils.java:157) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:108) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:278) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:239) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:606) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.mule.config.spring.SpringRegistry.doInitialise(SpringRegistry.java:108) ~[mule-module-spring-config-3.7.0.jar:3.7.0]
    at org.mule.registry.AbstractRegistry.initialise(AbstractRegistry.java:104) ~[mule-core-3.7.0.jar:3.7.0]
    at org.mule.config.spring.SpringXmlConfigurationBuilder.createSpringRegistry(SpringXmlConfigurationBuilder.java:172) ~[mule-module-spring-config-3.7.0.jar:3.7.0]
    at org.mule.config.spring.SpringXmlConfigurationBuilder.doConfigure(SpringXmlConfigurationBuilder.java:95) ~[mule-module-spring-config-3.7.0.jar:3.7.0]
    at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:43) ~[mule-core-3.7.0.jar:3.7.0]
    at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) ~[mule-core-3.7.0.jar:3.7.0]
    at org.mule.config.builders.AutoConfigurationBuilder.autoConfigure(AutoConfigurationBuilder.java:101) ~[mule-core-3.7.0.jar:3.7.0]
    at org.mule.config.builders.AutoConfigurationBuilder.doConfigure(AutoConfigurationBuilder.java:52) ~[mule-core-3.7.0.jar:3.7.0]
    at org.mule.config.builders.AbstractConfigurationBuilder.configure(AbstractConfigurationBuilder.java:43) ~[mule-core-3.7.0.jar:3.7.0]
    at org.mule.config.builders.AbstractResourceConfigurationBuilder.configure(AbstractResourceConfigurationBuilder.java:69) ~[mule-core-3.7.0.jar:3.7.0]
    at org.mule.context.DefaultMuleContextFactory$1.configure(DefaultMuleContextFactory.java:89) ~[mule-core-3.7.0.jar:3.7.0]
    at org.mule.context.DefaultMuleContextFactory.doCreateMuleContext(DefaultMuleContextFactory.java:222) ~[mule-core-3.7.0.jar:3.7.0]
    at org.mule.context.DefaultMuleContextFactory.createMuleContext(DefaultMuleContextFactory.java:81) ~[mule-core-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.application.DefaultMuleApplication.init(DefaultMuleApplication.java:188) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.artifact.ArtifactWrapper$2.execute(ArtifactWrapper.java:62) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.artifact.ArtifactWrapper.executeWithinArtifactClassLoader(ArtifactWrapper.java:129) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.artifact.ArtifactWrapper.init(ArtifactWrapper.java:57) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:25) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    ... 10 more
Caused by: java.lang.ClassNotFoundException: com.sap.conn.jco.JCoException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[?:1.8.0_121]
    at org.mule.module.launcher.FineGrainedControlClassLoader.findClass(FineGrainedControlClassLoader.java:175) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.MuleApplicationClassLoader.findClass(MuleApplicationClassLoader.java:134) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at org.mule.module.launcher.FineGrainedControlClassLoader.loadClass(FineGrainedControlClassLoader.java:119) ~[mule-module-launcher-3.7.0.jar:3.7.0]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_121]
    at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:1.8.0_121]

3 个答案:

答案 0 :(得分:1)

请将sapjco3的Maven范围更改为“已提供”,然后将sapjco3.dll和sapjco.jar放入tomcat lib文件夹中。

答案 1 :(得分:0)

如果找不到JCo类,则要么是因为sapjco3.jar实际上不在类路径中,要么JCo初始化失败,例如在加载其本机库时。

您是否选择了适合您的JVM(32位与64位)的正确JCo本机库?如果使用32位JVM,即使在64位操作系统上运行,也需要安装32位版本的JCo。

我不了解Mule,但SAP建议不要将sapjco3.jar与Java应用程序一起部署到应用程序服务器运行时环境中。由于JCo的本机库只能加载一次,因此最好将其视为系统库,即将其放入Mule启动类路径本身。否则,第二个应用程序(也包含sapjco3.jar)的启动可能会失败。

答案 2 :(得分:0)

如果你的项目是mavenized,那么将这个依赖项添加到POM:

<dependency>
<groupId>org.hibersap</groupId>
<artifactId>sapjco3</artifactId>
<version>3.0-RC02</version>
</dependency>