logstash-input-jdbc seems does not work with java11 (or maybe 9 and later)
due to jdk ClassLoading strategy changed after java 9.
Enviroment:
logstash 7.1.0
windows7-64
oracle jdk11.0.3
when run logstash by ./logstash.bat -f ./mysql/jdbc.conf
I got the following errors:
[2019-05-28T19:34:00,930][ERROR][logstash.inputs.jdbc ] Failed to load ./mysqlconn.jar {:exception=>#<TypeError: failed to coerce jdk.internal.loader.ClassLoaders$AppClassLoader to java.net.URLClassLoader>}
{ 2014 rufus-scheduler intercepted an error:
2014 job:
2014 Rufus::Scheduler::CronJob "* * * * *" {}
2014 error:
2014 2014
2014 LogStash::ConfigurationError
2014 com.mysql.jdbc.Driver not loaded. Are you sure you've included the correct jdbc driver in :jdbc_driver_library?
2014 D:/programs/EKL/logstash-7.1.0/vendor/bundle/jruby/2.5.0/gems/logstash-input-jdbc-4.3.13/lib/logstash/plugin_mixins/jdbc/jdbc.rb:163:in `open_jdbc_connection'
2014 D:/programs/EKL/logstash-7.1.0/vendor/bundle/jruby/2.5.0/gems/logstash-input-jdbc-4.3.13/lib/logstash/plugin_mixins/jdbc/jdbc.rb:221:in `execute_statement'
2014 D:/programs/EKL/logstash-7.1.0/vendor/bundle/jruby/2.5.0/gems/logstash-input-jdbc-4.3.13/lib/logstash/inputs/jdbc.rb:277:in `execute_query'
2014 D:/programs/EKL/logstash-7.1.0/vendor/bundle/jruby/2.5.0/gems/logstash-input-jdbc-4.3.13/lib/logstash/inputs/jdbc.rb:258:in `block in run'
2014 D:/programs/EKL/logstash-7.1.0/vendor/bundle/jruby/2.5.0/gems/rufus-scheduler-3.0.9/lib/rufus/scheduler/jobs.rb:234:in `do_call'
2014 D:/programs/EKL/logstash-7.1.0/vendor/bundle/jruby/2.5.0/gems/rufus-scheduler-3.0.9/lib/rufus/scheduler/jobs.rb:258:in `do_trigger'
2014 D:/programs/EKL/logstash-7.1.0/vendor/bundle/jruby/2.5.0/gems/rufus-scheduler-3.0.9/lib/rufus/scheduler/jobs.rb:300:in `block in start_work_thread'
2014 D:/programs/EKL/logstash-7.1.0/vendor/bundle/jruby/2.5.0/gems/rufus-scheduler-3.0.9/lib/rufus/scheduler/jobs.rb:299:in `block in start_work_thread'
2014 org/jruby/RubyKernel.java:1425:in `loop'
2014 D:/programs/EKL/logstash-7.1.0/vendor/bundle/jruby/2.5.0/gems/rufus-scheduler-3.0.9/lib/rufus/scheduler/jobs.rb:289:in `block in start_work_thread'
I looked into jdbc.rb (a ruby file) refered in the error log above, and here's the code cause the error (by class casting):
class_loader = java.lang.ClassLoader.getSystemClassLoader().to_java(java.net.URLClassLoader)
since java 9 , java.lang.ClassLoader.getSystemClassLoader no longer returns an instance of
URLClassLoader.
So I change java version from 11 to 8. reboot logstash, It works fine and a sql was executed as expected:
[2019-05-28T19:23:48,634][INFO ][logstash.javapipeline ] Pipeline started {"pipeline.id"=>"main"}
[2019-05-28T19:23:48,746][INFO ][logstash.agent ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[2019-05-28T19:23:49,297][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
D:/programs/EKL/logstash-7.1.0/vendor/bundle/jruby/2.5.0/gems/rufus-scheduler-3.0.9/lib/rufus/scheduler/cronline.rb:77: warning: constant ::Fixnum is deprecated
[2019-05-28T19:24:02,917][INFO ][logstash.inputs.jdbc ] (0.018358s) SELECT version()
[2019-05-28T19:24:02,978][INFO ][logstash.inputs.jdbc ] (0.000690s) SELECT version()
[2019-05-28T19:24:03,431][INFO ][logstash.inputs.jdbc ] (0.256872s) SELECT count(*) AS `count` FROM (SELECT * FROM PRODUCT) AS `t1` LIMIT 1
[2019-05-28T19:24:03,480][INFO ][logstash.inputs.jdbc ] (0.001593s) SELECT * FROM (SELECT * FROM PRODUCT) AS `t1` LIMIT 50000 OFFSET 0
Perhaps some one could fix it ?
Hope it would help.