SheppardDigital
SheppardDigital

Reputation: 3265

JClouds error: key [rackspace-cloudservers-uk] not in the list of providers or apis when using Shaded Jar

I have a spring boot project which I'm trying to integrate JClouds into so I can upload files to the Rackspace Cloud. In a previous question I found that jclouds doesn't really work with the latest version of Spring due to a conflict or something with Gson. Apache jclouds java.lang.NoSuchMethodError when using Rackspace in a Spring Boot application

In order to get around this, as suggested I've tried to create a shaded jar which contains both jclouds and gson, then I've put that into my Spring Boot project.

My Spring Boot project is using Embed Tomcat, and I'm using InteliJ. The class names etc for jclouds seem to be being picked up ok in InteliJ, but when I try to run the application I get the error;

Caused by: java.util.NoSuchElementException: key [cloudfiles-uk not in the list of providers or apis: {providers=[aws-cloudwatch], apis=[rackspace-cloudidentity]}
    at org.jclouds.ContextBuilder.newBuilder(ContextBuilder.java:173) ~[jclouds-shaded-1.0-SNAPSHOT.jar:na]

I don't know if this is an issue with my project or the shaded jar I created. Here's the POM I used to create the jar file.

<?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>digital.sheppard</groupId>
    <artifactId>jclouds-shaded</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.jclouds</groupId>
            <artifactId>jclouds-all</artifactId>
            <version>1.9.2</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>com.google.code.gson</pattern>
                                    <shadedPattern>com.shaded.code.gson</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

Upvotes: 0

Views: 157

Answers (1)

Ignasi Barrera
Ignasi Barrera

Reputation: 1476

You have to configure the ServicesResourceTransformer in the maven shade plugin, to make sure service loader files from all jars are merged into a single one.

Upvotes: 1

Related Questions