无法加载 Java class uk.co.jaywayco.Parser

cannot load Java class uk.co.jaywayco.Parser

我正在尝试编写自定义 logstash 过滤器。我已遵循文档 here.

我的过滤器(当时)看起来像:

# Call this file 'foo.rb' (in logstash/filters, as above)
require "logstash/filters/base"
require "logstash/namespace"

class LogStash::Filters::NLP < LogStash::Filters::Base

  # Setting the config_name here is required. This is how you
  # configure this filter from your logstash config.
  #
  # filter {
  #   foo { ... }
  # }
  config_name "nlp"

  # New plugins should start life at milestone 1.
  milestone 1

  # Replace the message with this value.
  config :message, :validate => :string

  public
  def register
    # nothing to do
    java_import 'uk.co.jaywayco.Parser'
  end # def register

  public
  def filter(event)
    # return nothing unless there's an actual filter event
    return unless filter?(event)
    if @message
      # Replace the event message with our message as configured in the
      # config file.
      event["message"] = @message
    end
    # filter_matched should go in the last line of our successful code
    filter_matched(event)
  end # def filter
end # class LogStash::Filters::NLP

我创建了一个非常简单的 logstash 配置,如下所示:

input {
  stdin { type => "nlp" }
}
filter {
  if [type] == "nlp" {
    nlp {
      message => "Hello world! - Youve been NLP'd"
    }
  }
}
output {
  stdout { }
}

当我 运行 logstash 使用以下命令时:

bin/logstash -f /etc/logstash/conf.d/test.conf

我收到以下错误:

The error reported is:
    enter code herecannot load Java class uk.co.jaywayco.Parser

java class uk.co.jaywayco.Parser 位于 /opt/logstash/lib/logstash/filters 文件夹中的 jar 文件中。这是所有过滤器脚本所在的位置。

为什么 logstash 不加载我的 java class?

好的,感谢 logstash IRC 频道

解决方案是在其他 require

的地方添加 require 'logstash/filters/myjarfile.jar'