ExceptionInInitializerError in Aspose Java for Ruby


I’m trying to read a PPT file with aspose java for Ruby, but it crashes before I get a chance to read the slides :

require 'rjb'
Rjb::add_jar( Dir.glob("#{Rails.root}/lib/jars/*.jar").join(':'))

puts "STARTED"

data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/' 
# Instantiate Presentation class that represents the presentation file

puts "DATADIR"
puts data_dir

presentation_class = Rjb::import('com.aspose.slides.Presentation')

presentation_instance = presentation_class.new(data_dir + 'test.pptx')

This gives me this output :

Error performing AsposeJob (Job ID: f4bd9e14-68d0-44df-b380-55d2dabbfef7) from Async(default) in 767.84ms: ExceptionInInitializerError (unknown exception):
/Users/Development/app/jobs/aspose_job.rb:18:in `import'
/Users/Development/app/jobs/aspose_job.rb:18:in `perform'

Line 18 is the import line : presentation_class = Rjb::import(‘com.aspose.slides.Presentation’)

Any idea what this might be ?
I’m running Rails 6 with the jar file aspose-slides-20.5-jdk16.jar

java version “14.0.1” 2020-04-14
Java™ SE Runtime Environment (build 14.0.1+7)
Java HotSpot™ 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)



Can you please try using following Ruby file on your end with your presentation using latest Aspose.Slides for Java 20.6 Jar file. This code works fine with attached presentation on my end. The generated presentation is also attached. If you still feel issue, then please share the source presentation reproducing the issue.

helloworld.zip (851 Bytes)
data.zip (47.1 KB)


Thanks a lot for your answer !
I don’t see a jar import statement in Rjb in your script, how would you import the jar ?
Because I believe that’s what is causing trouble in my script.

I tried adding this while putting aspose-slides-20.5-jdk16.jar in the same folder than the ruby script:

Rjb::add_jar( Dir.glob("*.jar").join(':'))

But got a classnotfound exception error.

➜  aspose ruby helloworld.rb
DATADIR ./data/
Traceback (most recent call last):
	1: from helloworld.rb:13:in `<main>'
helloworld.rb:13:in `import': ClassNotFoundException



I have used following commands to load the Jar file and execute the script on my end.

require 'rjb'


require 'C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/asposeslidesjava-0.0.2/lib/asposeslidesjava'
include Asposeslidesjava
include Asposeslidesjava::HelloWorld

Ok, so I necessarily need to put the jar in the gem folder itself, I can’t put it anywhere else ? That might be a pain in a production environment where gems might be installed differently depending on the server


It can be put anywhere. All you need to do is add and and load the Jar prior to execution of your Ruby code where it is referred.