I came across a use case where we needed a MapForce mapping in our Camel-K flow. MapForce generated Java code consists of many classes and it becomes overly cumbersome to add them all to the kamel run command. To solve this problem we put all the MapForce generated code into a .jar file and then added it to our cluster and referenced it in our kamel run command
1. First we made a .jar file out of the generated java code. For this we use the jar command that can be found in most java developer kits
jar cvf MapFormatAToFormatB.jar com/ se/
This creates a .jar file called MapFormatAToFormatB.jar with the contents of the generated code com/ and se/. Mapforce puts general classes into com/ package and our custom classes into your own packages, in our case se/.
2. Create a ConfigMap to hold our .jar so that Camel-K-Operator can use it
kubectl create configmap map-formata-to-formatb --from-file=MapFormatAToFormatB.jar
3. Reference the configmap in you kamel run command and add a trait to put it on the classpath
kamel run src/main/java/myApp --resource configmap:map-formata-to-formatb -t jvm.classpath=/etc/camel/resources/map-formata-to-formatb/MapFormatAToFormatB.jar
That´s it. In our code we reference these classes the same way we should have if the where part of our code base
import com.altova.io.Input; import com.altova.io.StringInput; import com.altova.io.StringOutput; import se.myorg.integration.MapFormatAToFormatB; import org.apache.camel.builder.RouteBuilder; public class AmbuReg extends RouteBuilder { @Override public void configure() throws Exception { ... } }
Tested on Camel-K-Operator v1.11.1 and Kubernetes v1.24.11
0 Comments.