kdgregory / log4j-aws-appenders

Appenders for Log4J 1.2.x, Log4J 2.x, and Logback that write to AWS destinations.
Apache License 2.0
67 stars 18 forks source link

java.lang.NoClassDefFoundError for ResourceAlreadyExistsException #145

Closed unoexperto closed 3 years ago

unoexperto commented 3 years ago

Looks like something was deprecated in AWS SDK. I'm using 2.16.3 and I get following exception on start

Exception in thread "main" java.lang.NoClassDefFoundError: software/amazon/awssdk/services/cloudwatchlogs/model/ResourceAlreadyExistsException
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:377)
    at com.kdgregory.logging.aws.facade.FacadeFactory.findImplementationClass(FacadeFactory.java:83)
    at com.kdgregory.logging.aws.facade.FacadeFactory.createFacade(FacadeFactory.java:38)
    at com.kdgregory.logging.aws.cloudwatch.CloudWatchWriterFactory.newLogWriter(CloudWatchWriterFactory.java:40)
    at com.kdgregory.logging.aws.cloudwatch.CloudWatchWriterFactory.newLogWriter(CloudWatchWriterFactory.java:28)
    at com.kdgregory.log4j2.aws.internal.AbstractAppender.startWriter(AbstractAppender.java:266)
    at com.kdgregory.log4j2.aws.internal.AbstractAppender.start(AbstractAppender.java:165)
    at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:304)
    at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:622)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:695)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:712)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:267)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:245)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:664)
kdgregory commented 3 years ago

@unoexperto - actually, this is the exception that you'll see if you don't include the CloudWatch Logs JAR in your deployment.

It could also happen if you use the V2 facade JAR from this library with a V1 AWS SDK.

unoexperto commented 3 years ago

@kdgregory I used V2 facade and 2.x version of AWS SDK. These are my dependencies

software.amazon.awssdk:aws-sdk-java:2.16.3
software.amazon.awssdk:logs:2.0.0-preview-11

From what I saw in the sources of the SDK logs:2.0.0-preview-11 is outdated and no longer used in it.

kdgregory commented 3 years ago

@unoexperto - if you're using 2.0.0-preview-11 for the logs JAR, that could be your problem. You should use the same version for all SDK JARs.

I can assure you that ResourceAlreadyExistsException is still in the SDK. It's in the current JavaDoc, and I checked the current source.

Lastly, I took my example program, deleted the dependency on the CloudWatch Logs JAR, and saw exactly that error.