[jruby] compiling assets via org.jruby.embed.IsolatedScriptingContainer

Cris Shupp cshupp at gmail.com
Fri Dec 9 21:45:28 JST 2016


compiling assets via org.jruby.embed.IsolatedScriptingContainer

If I take the following script:
#--------------------------BEGIN-------------
java_import 'org.jruby.embed.IsolatedScriptingContainer' do |pkg, cls|
'JScriptingContainer'
end

java_import 'org.jruby.embed.LocalContextScope' do |pkg, cls|
  'JLocalContextScope'
end

scriptlet =%{
$VERBOSE=nil
puts "Assets being compiled"
ENV['RAILS_ENV'] = 'production'
ENV['GEM_HOME'] = '#{ENV['GEM_HOME']}'
ARGV=['RAILS_ENV=production', 'assets:precompile']
require './config/boot'
require 'rake'
Rake.application.run
}

unless File.exists?('assets_compiled')
  require 'fileutils'
  FileUtils.touch('assets_compiled')
  container = JScriptingContainer.new(JLocalContextScope::SINGLETHREAD)
  env = container.getEnvironment
  #container.setCurrentDirectory(Rails.root.to_s)
  begin
    container.runScriptlet scriptlet
  rescue => ex
    puts "#{ex}"
    puts ex.backtrace.join("\n")
  end
end
#--------------------END----------------------

and run it in rails root via:

java -jar %JRUBY_JAR% compile_assets.rb

All of my assets compile as expected.

If I create an initializer called z_last.rb:
#------------------BEGIN---------------------
    java_import 'org.jruby.embed.IsolatedScriptingContainer' do |pkg, cls|
      'JScriptingContainer'
    end

java_import 'org.jruby.embed.LocalContextScope' do |pkg, cls|
  'JLocalContextScope'
end

scriptlet =%{
$VERBOSE=nil
puts "Assets being compiled"
ENV['RAILS_ENV'] = 'production'
ENV['GEM_HOME'] = '#{ENV['GEM_HOME']}'
ARGV=['RAILS_ENV=production', 'assets:precompile']
require './config/boot'
require 'rake'
Rake.application.run
}
unless File.exists?('assets_compiled')
  require 'fileutils'
  FileUtils.touch('assets_compiled')
  container = JScriptingContainer.new(JLocalContextScope::SINGLETHREAD)
  container.setCurrentDirectory(Rails.root.to_s)
  begin
    container.runScriptlet scriptlet
  rescue => ex
    $log.fatal "#{ex}"
    $log.fatal ex.backtrace.join("\n")
  end
end
#------------------END-------------

When I start my rails app it always partially creates my assets then
bombs as follows:

....various assets
I, [2016-12-08T18:03:21.578000 #12792]  INFO -- : Writing
C:/Appservers/apache-tomcat-8.0.32/webapps/rails_komet_a/WEB-INF/public/assets/icon_primitive_arrow-52ea5aae9ca5844701628ea2587dd54926
120187eb0ec2a1ef3dad7d39fb01ca.svg
I, [2016-12-08T18:03:21.584000 #12792]  INFO -- : Writing
C:/Appservers/apache-tomcat-8.0.32/webapps/rails_komet_a/WEB-INF/public/assets/icon_primitive_arrow-52ea5aae9ca5844701628ea2587dd54926
120187eb0ec2a1ef3dad7d39fb01ca.svg.gz
rake aborted!
Java::JavaLang::StringIndexOutOfBoundsException: String index out of
range: 3
java.lang.String.charAt(java/lang/String.java:658)
org.apache.catalina.loader.WebappClassLoaderBase.filter(org/apache/catalina/loader/WebappClassLoaderBase.java:2780)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(org/apache/catalina/loader/WebappClassLoaderBase.java:1253)
java.lang.ClassLoader.loadClass(java/lang/ClassLoader.java:411)
java.lang.ClassLoader.loadClass(java/lang/ClassLoader.java:357)
org.mozilla.javascript.Kit.classOrNull(org/mozilla/javascript/Kit.java:60)
org.mozilla.javascript.NativeJavaPackage.getPkgProperty(org/mozilla/javascript/NativeJavaPackage.java:129)

Any ideas why?

Thanks,

Cris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ruby-lang.org/pipermail/jruby/attachments/20161209/2e04b08f/attachment.html>


More information about the JRuby mailing list