Loading

How to Fix the MuleSoft Error JAVA:CLASS_NOT_FOUND Using the Java Connector in Mule 4

Publish Date: Jun 20, 2025
Description

You have an application and you are using the Java component to invoke methods or create instances of classes, and you receive an error that contains "JAVA: CLASS_NOT_FOUND" as shown here:

org.mule.runtime.core.internal.exception.OnErrorPropagateHandler: 
********************************************************************************
Message               : Failed to load Class with name [com.mycompany.MyClass]. Class not found.
Error type            : JAVA:CLASS_NOT_FOUND
Element               : testFlow1/processors/0 @ test:test.xml:43 (New)
Element XML           : <java:new doc:name="New" doc:id="df09b56d-3d86-4a60-aa52-f421393d82a7" class="com.mycompany.MyClass" constructor="DateTime()"></java:new>

  (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
Resolution

CAUSE

Mule 4 introduced class-loading isolation, which means that unless the resources have been shared, they won't be available to be used by the connectors. This includes drivers, external libraries, and Java code included in the project.  You can find more information on this feature in the Help on Class Loading Isolation.

SOLUTION

Depending on where the class is packaged, there are different alternatives to address this error.

1. The class is located in the project

In this case, you need to follow the steps mentioned in the Help on How to Export Java Classes.

2. The class is contained in a jar file

In this case, you need to add the dependency to your project and then share it using the mule-maven plugin. For example, if I have the class com.mycompany.MyClass in a mavenized jar, then I will need to do as follows:

  1. Add the dependency to your pom.xml:
    <dependencies>
        <!-- more dependencies -->
        <dependency>
            <groupId>com.mycompany</groupId>
            <artifactId>my-library</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>
  1. Edit the mule-maven plugin to share that dependency:
<plugin>
    <groupId>org.mule.tools.maven</groupId>
    <artifactId>mule-maven-plugin</artifactId>
    <version>${mule.maven.plugin.version}</version>
    <extensions>true</extensions>
    <configuration>
        <sharedLibraries>
            <!-- other shared libraries -->
            <sharedLibrary>
                <groupId>com.mycompany</groupId>
                <artifactId>my-library</artifactId>
            </sharedLibrary>
        </sharedLibraries>
    </configuration>
</plugin>


 

Knowledge Article Number

001118381

 
Loading
Salesforce Help | Article