Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

When I try to deploy an application to my Mule standalone server, the application deploys properly but when I try running a flow which uses RestTemplate (spring) and HttpComponentsClientHttpRequestFactory (apache http components) to bypass proxy issues, it gives me the following error:

java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpUriRequest

Funny part is, if I run the same exactly mule application in the embedded version, it loads fine. (probably because the libraries are transparently added to the runtime classpath?)

I know I can fix this by putting the httpclient/httpcore libraries inside Mule's endorsed libraries folder, but I fine this pesky having to move library around. I am using maven, so I expect all the libraries to be managed by Maven...

I know the library gets loaded, because mule logs tells me it finds the library.

Here's my pom.xml:

<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>xxx</groupId>
<artifactId>xxx</artifactId>
<version>1.0.0</version>
<packaging>mule</packaging>
<name>xxx</name>

<properties>
    <mule.version>3.4.0</mule.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

    <dependency>
        <groupId>org.mule.tools</groupId>
        <artifactId>maven-mule-plugin</artifactId>
        <version>1.9</version>
    </dependency>

    <dependency>
        <groupId>org.mule</groupId>
        <artifactId>mule-core</artifactId>
        <version>${mule.version}</version>
    </dependency>

    <dependency>
        <groupId>org.mule.transports</groupId>
        <artifactId>mule-transport-vm</artifactId>
        <version>${mule.version}</version>
    </dependency>

    <dependency>
        <groupId>org.mule.transports</groupId>
        <artifactId>mule-transport-http</artifactId>
        <version>${mule.version}</version>
    </dependency>

    <dependency>
        <groupId>org.mule.modules</groupId>
        <artifactId>mule-module-jersey</artifactId>
        <version>${mule.version}</version>
    </dependency>

    <dependency>
        <groupId>org.mule.modules</groupId>
        <artifactId>mule-module-xml</artifactId>
        <version>${mule.version}</version>
    </dependency>

    <dependency>
        <groupId>org.mule.modules</groupId>
        <artifactId>mule-module-scripting</artifactId>
        <version>${mule.version}</version>
    </dependency>

    <dependency>
        <groupId>org.mule.tests</groupId>
        <artifactId>mule-tests-functional</artifactId>
        <version>${mule.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.4</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2.5</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.2.6</version>
    </dependency>

</dependencies>

<build>
    <defaultGoal>install</defaultGoal>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.4</version>
            </plugin>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.mule.tools</groupId>
                                    <artifactId>maven-mule-plugin</artifactId>
                                    <versionRange>[1.9,)</versionRange>
                                    <goals>
                                        <goal>attach-test-resources</goal>
                                        <goal>
                                            filter-resources
                                        </goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <encoding>ISO-8859-1</encoding>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.mule.tools</groupId>
            <artifactId>maven-mule-plugin</artifactId>
            <version>1.9</version>
            <extensions>true</extensions>
            <configuration>
                <copyToAppsDirectory>true</copyToAppsDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

share|improve this question
I believe the problem is that mule uses the httpclient 3.x while the class HttpUriRequest is part of the 4.x jar. Can you share your pom? – genjosanzo yesterday
@genjosanzo I've added the pom.xml to my question, thanks. I already figured that the httpclient 3.x has a higher priority over my library, but I'm not sure how to override it. I already tried the classloader overriding. "loader.override=org.apache.http" – TheAJ yesterday

1 Answer

Mule does provide the httpclient jar, however it provides an older version that does not include the HttpUriRequest class.

If you want to use that class, or anything from that jar, you should not declare it as provided and let the jar (an all the needed dependencies) be copied into the generated application lib folder

share|improve this answer
Sorry, I added "provided" scope afterwards. It's there because I added the newer httpclient 4.2.5 inside Mule's library folder, which solved the issue. I still think there's a more robust conclusion to this. – TheAJ yesterday
If you don't declare it has provided, does the library get copied int the app lib folder? – genjosanzo yesterday
Yes, it does get copied into app/lib/ folder – TheAJ yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.