Karaf自定义appender以错误开头:java.lang.NoClassDefFoundError:javax / crypto / SecretKey

时间:2015-03-25 00:19:36

标签: log4j appender karaf

我是一个自定义的log4j自定义appender,它在我的测试环境中工作,如:
C:\ Log4jTest> java -cp。 Log4jTest

但是在将其配置为Karaf时,启动时总是会抛出错误: org.apache.felix.configadmin-1.2.8 | [org.osgi.service.log.LogService,org.knopflerfish.service.log.LogService,org.ops4j.pax.logging.PaxLoggingService,org.osgi.service.cm .ManagedService,id = 8,bundle = 4]:意外问题更新配置PID = org.ops4j.pax.logging,factoryPID = null,bundleLocation = mvn:org.ops4j.pax.logging / pax-logging-service / 1.6。 9 java.lang.NoClassDefFoundError:javax / crypto / SecretKey     在com.microsoft.azure.storage.Credentials。(Credentials.java:63)     在com.microsoft.azure.storage.StorageCredentialsAccountAndKey。(StorageCredentialsAccountAndKey.java:42) ......
我的mvn POM.XML非常简单:

[<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.hcit.logger</groupId>
  <artifactId>cloud-logger-service</artifactId>
  <version>1.0.0</version>
  <packaging>bundle</packaging>
  <dependencies>
    <dependency>
      <groupId>org.ops4j.pax.logging</groupId>
      <artifactId>pax-logging-service</artifactId>
      <version>1.6.9</version>
    </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-storage</artifactId>
            <version>1.1.0</version>
        </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>2.3.7</version>
        <extensions>true</extensions>   
        <configuration>
          <instructions>
            <Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
            <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
            <Export-Package>com.hcit.logger</Export-Package>
            <Import-Package>!*</Import-Package>
            <Embed-Dependency>*;scope=compile|runtime;inline=true</Embed-Dependency>
            <_failok>true</_failok>
            <Fragment-Host>org.ops4j.pax.logging.pax-logging-service</Fragment-Host>
            <Implementation-Version>${project.version}</Implementation-Version>
            <Bundle-Version>${project.version}</Bundle-Version>
          </instructions>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
]

我的org.ops4j.pax.logging.cfg的片段:
....
log4j.appender.hafauditCloudLoggerAppender = com.hcit.logger.CloudLoggerAppender
log4j.appender.hafauditCloudLoggerAppender.Threshold = DEBUG
log4j.appender.hafauditCloudLoggerAppender.TableName = LoggerTable
log4j.category.com.gehcit.haf.audit.consumer = DEBUG,hafauditCloudLoggerAppender ......

我检查过我的jre.properties确实有javax.crypto:
......
 javax.crypto,\
 javax.crypto.interfaces,\
 javax.crypto.spec,\
......

我是卡拉夫的新手,想知道如何解决它?我的JDK是jdk1.7.0_72并且谢谢。

1 个答案:

答案 0 :(得分:0)

最后我发现了一些技巧,如果通过添加这样的组件来改变config.properties:
org.osgi.framework.bootdelegation = org.apache.karaf.jaas.boot,周日,的com.sun。,javax.transaction的,javax.transaction的。,javax.sql中。< /em>,oracle.,com.microsoft.sqlserver。,javax.crypto,javax.crypto。,javax.xml。,com.fasterxml。*

有效。 当然在POM.xml中应该添加fastxml的依赖关系:

   [<dependency>
       <groupId>de.matrixweb.smaller</groupId>
       <artifactId>ant</artifactId>
       <version>0.8.4</version>
    </dependency>]