Third party jar is not working

#1

Hi Friend , I am working on lucee with kafka.

my code is available in lucee/www direcotry and my kafka client jar is available in lucee/www/lib direcotry with the name kafka-clients-0.11.0.1.jar.

I am trying to send a message to the consumer using kafka.
I started zookeeper, kafka server , topic created sucessfully

my kafka producer and consumer is available in lucee/www/com directory, when kafkaProducer.cfc is executing its throwing class not found exception on below lines -

var ProducerConfig = createobject('java', 'org.apache.kafka.clients.producer.ProducerConfig');
    var StringSerializer = createobject('java', 'org.apache.kafka.common.serialization.StringSerializer');

below is the complete code for kafkaProducer.cfc file -

component accessors="true" {
  property producer;
  
  function init() {
    var props = createobject('java', 'java.util.Properties');
    var ProducerConfig = createobject('java', 'org.apache.kafka.clients.producer.ProducerConfig');
    var StringSerializer = createobject('java', 'org.apache.kafka.common.serialization.StringSerializer');
    
    props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"127.0.0.1:9092");
    
    props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
    props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());

    producer = createobject('java', 'org.apache.kafka.clients.producer.KafkaProducer').init(props);
    return this;
  }
  
  function send(topic, message) {
    var value = serializeJson(message);
    var producerrecord = createobject('java', 'org.apache.kafka.clients.producer.ProducerRecord').init(topic, value);
    getproducer().send(producerRecord);
  }
}

I think the kafka client jar is loading successfully, can you please help to understand how to use third part jar in my program.

Thanks in Advance for your kind support.

#2

Hi rohit,
when lucee/www is your web-root directory than lucee/www/lib is not the default location for loading jars.
Since you dont use the default folder (which would be for example: lucee/context/lib or web-inf/lucee/lib, and are autoloaded and visible in the lucee-webinterface), you can use the " this.javaSettings.loadPaths" in the application.cfc to load your jar file.