Run Logstash in Java using JRuby

Hi,

My final goal is to run Logstash within Tomcat (hence, packaged in a WAR file).
Has anybody some experience with that?
To gain some experience in running logstash within Java, I'm trying to start it in a small Java application.

I've added JRuby in my dependencies:

<dependency>
  <groupId>org.jruby</groupId>  
  <artifactId>jruby-complete</artifactId>
  <version>9.0.5.0</version>
</dependency>

I'm using these environment variables (not sure which are really needed):

jffi.boot.library.path = {LOGSTASHHOME}/vendor/jruby/lib/jni
jruby.home = {LOGSTASHHOME}/vendor/jruby
jruby.lib = {LOGSTASHHOME}/vendor/jruby/lib
jruby.script = jruby
jruby.shell = /bin/sh
LS_HOME = {LOGSTASHHOME}
RUBYLIB = {LOGSTASHHOME}/lib
GEM_HOME = {LOGSTASHHOME}/vendor/bundle/jruby/1.9/
GEM_PATH = {LOGSTASHHOME}/vendor/bundle/jruby/1.9/

These are my runtime parameters:

--1.9
{LOGSTASHHOME}/lib/bootstrap/environment.rb
logstash/runner.rb
agent
--config
{PIPELINECONFIG}
--log
{LOGFILE}

(Obviously, all placeholders are replaced accordingly)

And this is the code I use to (well, at least try to) start logstash:

File jrubyHome = new File({LOGSTASHHOME}, "vendor/jruby/"); 
        
RubyInstanceConfig config = new RubyInstanceConfig();
config.setJRubyHome(jrubyHome.getAbsolutePath());
config.setCurrentDirectory({LOGSTASHHOME}.getAbsolutePath());
config.setLoader(this.getClass().getClassLoader());
config.setEnvironment(envMap);
config.setLoadGemfile(true);

Main jrubyMain = new Main(config);
Status status = jrubyMain.run(args); 

This is the result that I get so far:

warning: --1.9 ignored
Exception in thread "main" org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- rubygems
    at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:937)
    at RUBY.<top>(file:/Users/roman/.m2/repository/org/jruby/jruby-complete/9.0.5.0/jruby-complete-9.0.5.0.jar!/jruby/bundler/startup.rb:3)

Quite embarrassingly, I don't have any experience with Ruby and JRuby, so any help is highly appreciated.

Is this the correct approach? What am I missing?

I also tried to use the JRuby package that comes with logstash (added the vendor/jruby/lib/jruby.jar JAR file to the Classloader at runtime and start it with reflection), but I would really like to use JRuby without reflection.

I'm aware that this is not a supported way of starting logstash, but we the strict requirement to start everything as a WAR container in Tomcat.

Thanks,
Roman