Joe Lat
Joe Lat

Reputation: 81

Issue Integrating Custom Java Maven Library in Mule Flow

I am new to Mule and Anypoint Studio, and I'm trying to integrate a custom Java Maven library project into a Mule flow. I've followed these steps:

After reviewing some blogs, I found that additional dependencies may need to be set under sharedLibraries.

<plugin>
    <groupId>org.mule.tools.maven</groupId>
    <artifactId>mule-maven-plugin</artifactId>
    <version>${mule.maven.plugin.version}</version>
    <extensions>true</extensions>
    <configuration>
        <classifier>mule-application</classifier>
        <sharedLibraries>
            <sharedLibrary>
                <groupId>ca.fhir.spike</groupId>
                <artifactId>custom-lib</artifactId>
                <version>1.0.0</version>
            </sharedLibrary>
        </sharedLibraries>
    </configuration>
</plugin>

However, when I tried this, I encountered another error during the build:

[ERROR] Failed to execute goal org.mule.tools.maven:mule-maven-plugin:4.2.0:clean (default-clean) on project abc-api: Unable to parse configuration of mojo org.mule.tools.maven:mule-maven-plugin:4.2.0:clean for parameter version: Cannot find 'version' in class org.mule.tools.api.classloader.model.SharedLibraryDependency -> [Help 1]

I also attempted to directly add the jar as a third-party jar but faced the same "Couldn't find class" error.

Below are my code snippet:

pom.xml for Java Lib:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ca.fhir.spike</groupId>
    <artifactId>custom-lib</artifactId>
    <version>1.0.0</version>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <dependencies>
    </dependencies>
</project>

Java Class:

package ca.fhir.spike;

public class FhirRulesValidation {
    public void validation(){
        System.out.println("Validation Completed");
    }
}

Mule Flow:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:java="http://www.mulesoft.org/schema/mule/java" xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/java http://www.mulesoft.org/schema/mule/java/current/mule-java.xsd">
    <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="44a7b392-87a9-43bd-8c4b-968564e857c9" >
        <http:listener-connection host="0.0.0.0" port="8081" />
    </http:listener-config>
    <flow name="java-integrationFlow" doc:id="0b431596-7c6e-48e2-8f1e-6dacf3ac7031" >
        <http:listener doc:name="Listener" doc:id="71890145-83be-4196-bf30-876abdd69442" path="/validation" allowedMethods="GET" config-ref="HTTP_Listener_config"/>
        <java:new doc:name="New" doc:id="331d81e5-28a4-421b-b671-b284f66fb276" class="ca.fhir.spike.FhirRulesValidation" constructor="FhirRulesValidation()" target="resultValidation"/>
        <java:invoke method="validation()" doc:name="Invoke" doc:id="3f42d15a-040d-4d0e-9175-d925a7d74167" instance="resultValidation" class="ca.fhir.spike.FhirRulesValidation"/>
    </flow>
</mule>

pom.xml for Mule Project

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mycompany</groupId>
    <artifactId>java-integration</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>mule-application</packaging>

    <name>java-integration</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <app.runtime>4.7.0</app.runtime>
        <mule.maven.plugin.version>4.2.0</mule.maven.plugin.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.2.0</version>
            </plugin>
            <plugin>
                <groupId>org.mule.tools.maven</groupId>
                <artifactId>mule-maven-plugin</artifactId>
                <version>${mule.maven.plugin.version}</version>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <compilerArgs>
                        <args>-parameters</args>
                    </compilerArgs>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-http-connector</artifactId>
            <version>1.9.3</version>
            <classifier>mule-plugin</classifier>
        </dependency>
        <dependency>
            <groupId>org.mule.connectors</groupId>
            <artifactId>mule-sockets-connector</artifactId>
            <version>1.2.4</version>
            <classifier>mule-plugin</classifier>
        </dependency>
        <dependency>
            <groupId>org.mule.module</groupId>
            <artifactId>mule-java-module</artifactId>
            <version>1.2.13</version>
            <classifier>mule-plugin</classifier>
        </dependency>
        <dependency>
            <groupId>ca.fhir.spike</groupId>
            <artifactId>custom-lib</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>anypoint-exchange-v3</id>
            <name>Anypoint Exchange</name>
            <url>https://maven.anypoint.mulesoft.com/api/v3/maven</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>mulesoft-releases</id>
            <name>MuleSoft Releases Repository</name>
            <url>https://repository.mulesoft.org/releases/</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>mulesoft-releases</id>
            <name>MuleSoft Releases Repository</name>
            <layout>default</layout>
            <url>https://repository.mulesoft.org/releases/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>

Could you please help me resolve this issue.

Upvotes: 0

Views: 80

Answers (2)

Shivakumar Shiva
Shivakumar Shiva

Reputation: 1

you need to export a resources in mule Ref https://docs.mulesoft.com/mule-runtime/latest/how-to-export-resources

Upvotes: 0

aled
aled

Reputation: 25664

The second error is because the shared library configuration should not have a version:

            <sharedLibrary>
                <groupId>ca.fhir.spike</groupId>
                <artifactId>custom-lib</artifactId>
            </sharedLibrary>

Upvotes: 0

Related Questions