我正在尝试将jruby嵌入到weblogic应用程序中以运行sass /指南针而没有运气;-( 这是迄今为止所做的:
安装sass / compass GEMS:
java -jar jruby-complete-1.7.10.jar -S gem install -i . compass --no-rdoc --no-ri
创建一个包含所有宝石的jar
jar uf jruby-complete-1.7.10.jar -C sass-compass .
检查新的jruby-complete-1.7.10.jar是否包含所有宝石:
java -jar jruby-complete-1.7.10.jar -S gem list
*** LOCAL GEMS ***
bouncy-castle-java (1.5.0147)
chunky_png (1.2.9)
compass (0.12.2)
fssm (0.2.10)
jruby-openssl (0.9.3)
json (1.8.0 java)
krypt (0.0.1)
krypt-core (0.0.1 universal-java)
krypt-provider-jdk (0.0.1)
rake (10.1.0)
rdoc (4.0.1)
sass (3.2.14)
到目前为止,这么好,我确认我的新超级jruby-complete-1.7.10.jar包含sass和指南针宝石
进入weblogic(Weblogic 11 - Oracle 10.3.6)
部署耳朵使结构如下:
MyEAR
|-APP-INF
| |-classes
| |-lib
| |-jruby-complete-1.7.10.jar <- my jruby jar that contains sass/compass gems
|-META-INF
|-MyWAR
|-META-INF
|-WEB-INF
|-classes
| |-MyServlet.class <- the servlet that compiles sass
|-lib
|-web.xml
当我调用servlet编译一些sass / compass css时,我收到以下错误:
LoadError: no such file to load -- sass/plugin
require at org/jruby/RubyKernel.java:1083
require at classpath:/META-INF/jruby.home/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:55
(root)at:2
为了编译我的sass /指南针样式,我要运行以下ruby脚本:
require 'rubygems'
require 'sass/plugin'
require 'sass/engine'
source = '...the scss code....'
engine = Sass::Engine.new(source,{ :syntax => :scss, :compass => {:css_dir => '/styles',:js_dir => '/scripts',images_dir => '/images'} })
result = engine.render
所以在我的servlet中我使用jruby:
ScriptingContainer rubyEngine = new ScriptingContainer(LocalContextScope.CONCURRENT);
String rubyScript = ...
final StringWriter rawScript = new StringWriter();
rawScript.append(rubyScript);
rubyScript.flush();
String compiledCSS = rubyEngine.runScriptlet(theScript)
.toString();
**没有运气**我得到了LoadError:没有这样的文件要加载 - sass / plugin
所以我尝试将LOAD_PATH设置为:
List<String> paths = new ArrayList<String>();
paths.add("classpath:/gems/sass-3.2.14/lib");
rubyEngine .setLoadPaths(paths);
**没有运气**
¿任何想法?
提前致谢
答案 0 :(得分:0)
Tom的线索解决方案是在LOAD_PATH上放置sass / compass gems路径。
所以在weblogic 10.3.6下运行sass / compass的脚本是:
sassGemDir = 'D:/compass-gems/gems/sass-3.2.13/lib'
compassGemDir = 'D:/compass-gems/gems/compass-0.12.2/lib'
chunkyPngGemDir = 'D:/compass-gems/gems/chunky_png-1.2.9/lib'
fssmGemDir = 'D:/compass-gems/gems/fssm-0.2.10/lib'
$LOAD_PATH.insert(0,sassGemDir,remoteSassGemDir,compassGemDir,chunkyPngGemDir,fssmGemDir)
require 'rubygems'
require 'sass/plugin'
require 'sass/engine'
source = '...the scss code....'
engine = Sass::Engine.new(source,{ :syntax => :scss,:compass => {:css_dir => '/styles',:js_dir => '/scripts',images_dir => '/images'} })
result = engine.render
注意:强>
最后我没有设法从JAR中制作jruby load sass / compass,所以不需要创建一个包含jruby-complete和sass / compass的超级jar(我的问题中的第2步)
从JAR 运行sass / compass 的ruby脚本中唯一的变化是:
sassGemDir = 'classpath:/gems/sass-3.2.13/lib'
compassGemDir = 'classpath/compass-0.12.2/lib'
chunkyPngGemDir = 'classpath/gems/chunky_png-1.2.9/lib'
fssmGemDir = 'classpath/gems/fssm-0.2.10/lib'
但是当我从优步罐中运行sass / compass加载时,我遇到了两个错误:
指南针的sprite-importer.rb无法加载sprite_importer.erb文件,因为它已加载如下:
TEMPLATE_FOLDER = File.join(File.expand_path('../', __FILE__), 'sprite_importer')
所以我将sprite-importer.rb更改为:
TEMPLATE_FOLDER = File.join( File.expand_path(File.join(File.dirname(__FILE__))),'sprite_importer')
这个问题消失了
指南针的frameworks.rb无法加载框架dir:当dir在JAR中时,jruby无法加载dir的内容(我认为它是java 6或jrockit的错误,这是我在weblogic中使用的JDK 10.3.6)
我找不到解决这个问题的方法,所以我切换到加载sass / compass来直接从文件系统加载而不是从JAR文件加载
最终说明 在Java 7下运行TOMCAT时,从JAR中加载GEM LOAD_PATH和指南针的所有问题都不是问题
希望这可以帮助那些尝试使用嵌入式jruby运行sass / compass的人