Please help! Getting file not found error running Sass and Compass as jar in ant

1,311 views
Skip to first unread message

axyl

unread,
Dec 1, 2011, 8:54:25 PM12/1/11
to Compass
I'm trying to get compass runnable from ant so we can include it in
our build process. I used the following tutorial to add compass as a
target in ant: http://caueguerra.com/tutorial-using-sass-in-a-java-project

Here are the gems in my uber-jar containing jruby:
> java -jar jruby-compass-gems.jar -S gem list

*** LOCAL GEMS ***

chunky_png (1.2.5)
compass (0.11.5)
fssm (0.2.7)
rake (0.8.7)
sass (3.1.1)
sources (0.0.1)


Here is my ant target for calling compass compile, just simpler than
the tutorial so I can put all files in one place:
<project name="run-compass" basedir=".">
<property name="apps.root" value="${basedir}/src/main/webapp/
apps" />
<property name="sass.dir" value="${apps.root}/resources/sass" />

<!-- Include jruby-compass jar -->
<path id="jruby.classpath">
<fileset dir="${basedir}">
<include name="jruby*.jar"/>
</fileset>
</path>

<target name="compile.sass">
<java classname="org.jruby.Main" fork="true" failonerror="true"
classpathref="jruby.classpath">
<arg line="${basedir}/compile.rb ${basedir} compile $
{sass.dir}"/>
</java>
</target>
</project>


With below modifications to compile.rb:
# Instead of loading lib dirs, just add the first arg
# Dir.entries(ARGV[0]).each do |lib|
# $LOAD_PATH.unshift "#{ARGV[0]}/#{lib}/lib"
#end
$LOAD_PATH.unshift "#{ARGV[0]}"

require 'rubygems'
require 'compass'
require 'compass/exec'

# select_appropriate_command_line_ui is no longer a valid method, so
don't use
#command_line_class =
Compass::Exec::Helpers.select_appropriate_command_line_ui [ARGV[1],
ARGV[2], "-q"]
exit Compass::Exec::SubCommandUI.new([ARGV[1], ARGV[2], "-q"]).run!


I see this error in the generated .css file after running ant:
Syntax error: File to import not found or unreadable: shared.
Load paths:
C:\Users\aliu\workspace\ui/src/main/webapp/apps/
resources/sass
file:C:/Users/aliu/workspace/ui/jruby-compass-
gems.jar!/gems/compass-0.11.5/frameworks/blueprint/stylesheets
file:C:/Users/aliu/workspace/ui/jruby-compass-
gems.jar!/gems/compass-0.11.5/frameworks/compass/stylesheets
C:/Users/aliu/workspace/ui/src/main/webapp/apps/
resources/sass/../../../lib/ext-4.0.7/resources/themes/stylesheets
Compass::SpriteImporter
on line 1 of file:C:/Users/aliu/workspace/ui/jruby-compass-
gems.jar!/gems/compass-0.11.5/frameworks/compass/stylesheets/compass/
css3/_border-radius.scss
from line 1 of file:C:/Users/aliu/workspace/ui/jruby-compass-
gems.jar!/gems/compass-0.11.5/frameworks/compass/stylesheets/compass/
_css3.scss


The offending line in _border-radius.scss is:
@import "shared";


Notice the load path contains compass stylesheets. I find it really
strange that compass was able to find _border-radius.scss, but not
_shared.scss, because they're in the same directory. I checked the jar
content to make sure _shared.scss exists. I tested running compile.rb
in the ${basedir} directly:
compile.rb . compile src\main\webapp\apps\resources\sass

It worked and created the .css file correctly, which means the problem
seems to lie in running from ant, or maybe jruby. Has anyone
experience something similar, or could give some insight to this
problem? Any suggestion appreciated!

Franz Heidl

unread,
Jan 23, 2012, 9:00:13 AM1/23/12
to Compass
We're having the exact same problem here. Apparently @imports
generally fail when referencing a file in the exact same directory as
the file that contains the @import directive. We do not have a
solution yet either.

axyl

unread,
Jan 30, 2012, 5:49:53 PM1/30/12
to Compass
Hey Franz,

I was able to discover a workaround, though it's a bit painful. I
realized that while @import "shared" cannot be found, @import "compass/
css3/shared" is okay, so I modified all such local @imports in compass
stylesheets to reference the more absolute paths before packaging
compass up into the jar.

Compass team, is it possible for you to incorporate this workaround?

On Jan 23, 6:00 am, Franz Heidl <lastmodernis...@googlemail.com>
wrote:

Franz Heidl

unread,
Feb 17, 2012, 4:07:04 AM2/17/12
to Compass
Hi,
sorry for getting back so late.
We were considering this option, but having to manually change paths
throughout Compass turned out not to be an option when we're headed
towards full build/deployment automation.

What we do now is to extract Compass from out of the .jar at a
relatively early stage of the Maven build so it actually exists in a
directory once the compile is happening, and then all is well and all
the @import directives work just fine!

Probably not an ideal or overly elegenat solution, but it does work
and saves us from the hassle of manually changing paths in all the
Compass files.

If you need any more details on how exactly we do this let me know and
I can try to head one of our devs to this group, I am an Designer/
Frontend Developer and my understanidng of all things build/Maven, etc
is pretty limited I have to admit.

Best,
Franz

cgonzales

unread,
Feb 20, 2012, 9:09:30 PM2/20/12
to Compass
Hi-

I've also been struggling to get compass to run from a jar following
Axyl's modifications to the original tutorial. I get an error that it
can't find compass/reset. I'm also a frontend guy and have been
stumbling my way through Maven build tasks. If you could shared how
you extract Compass from the jar as part of a Maven build I'd
appreciate it.

Thanks,
Chris

On Feb 17, 4:07 am, Franz Heidl <lastmodernis...@googlemail.com>
wrote:
> Hi,
> sorry for getting back so late.
> We were considering this option, but having to manually change paths
> throughout Compass turned outnotto be an option when we're headed
> towards full build/deployment automation.
>
> What we do now is to extract Compass from out of the .jar at a
> relatively early stage of the Maven build so it actually exists in a
> directory once the compile is happening, and then all is well and all
> the @import directives work just fine!
>
> Probablynotan ideal or overly elegenat solution, but it does work

axyl

unread,
May 18, 2012, 6:26:50 PM5/18/12
to compas...@googlegroups.com
I tried updating the Compass jar recently. JRuby is now at 1.6.7.2 as well. Ran into a different issue which I'll describe below, and for which I did find a solution that works. 

My gems are now as following:
$ java -jar jruby-compass-gems.jar -S gem list

*** LOCAL GEMS ***

chunky_png (1.2.5)
compass (0.12.1)
fssm (0.2.9)
rake (0.8.7)
sass (3.1.18)
sources (0.0.1)

I created the jar w/o my workaround, to see if it's fixed. However, it actually got worse because now 'compass/css' can't even be found anymore:
     [java] Sass::SyntaxError on line 1 of C: File to import not found or unreadable: compass/css3.
     [java] Load paths:
     [java]   C:/Users/aliu/workspace/ui/resources/apps-resources/sass
     [java]   C:/Users/aliu/workspace/ui/resources/lib/extjs-4.1.0/resources/themes/stylesheets
     [java]   Compass::SpriteImporter
     [java]   C:/Users/aliu/workspace/ui/resources/apps-resources/sass/ri-all.scss:4
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/import_node.rb:64:in `import'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/import_node.rb:25:in `imported_file'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/perform.rb:149:in `visit_import'
     [java]   org/jruby/RubyKernel.java:2080:in `send'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/base.rb:37:in `visit'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/perform.rb:18:in `visit'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/perform.rb:146:in `visit_import'
     [java]   org/jruby/RubyArray.java:2331:in `collect'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/perform.rb:146:in `visit_import'
     [java]   org/jruby/RubyKernel.java:2080:in `send'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/base.rb:37:in `visit'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/perform.rb:18:in `visit'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/base.rb:53:in `visit_children'
     [java]   org/jruby/RubyArray.java:2331:in `collect'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/base.rb:53:in `visit_children'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/perform.rb:27:in `visit_children'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/perform.rb:39:in `with_environment'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/perform.rb:26:in `visit_children'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/base.rb:37:in `visit'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/perform.rb:47:in `visit_root'
     [java]   org/jruby/RubyKernel.java:2080:in `send'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/base.rb:37:in `visit'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/perform.rb:18:in `visit'
     [java]   org/jruby/RubyKernel.java:2080:in `send'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/visitors/perform.rb:7:in `visit'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/tree/root_node.rb:20:in `render'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/engine.rb:299:in `_render'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/sass-3.1.18/lib/sass/engine.rb:246:in `render'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/compiler.rb:140:in `compile'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/compiler.rb:126:in `timed'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/compiler.rb:139:in `compile'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/logger.rb:45:in `red'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/compiler.rb:138:in `compile'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/compiler.rb:118:in `compile_if_required'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/compiler.rb:103:in `run'
     [java]   org/jruby/RubyArray.java:1615:in `each'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/compiler.rb:101:in `run'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/compiler.rb:126:in `timed'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/compiler.rb:100:in `run'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/commands/update_project.rb:45:in `perform'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/commands/base.rb:18:in `execute'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/commands/project_base.rb:19:in `execute'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/exec/sub_command_ui.rb:43:in `perform!'
     [java]   file:C:/Users/aliu/workspace/ui/build/compass/jruby-compass-gems.jar!/gems/compass-0.12.1/lib/compass/exec/sub_command_ui.rb:15:in `run!'
     [java]   C:\Users\aliu\workspace\ui\build\compass/run-compass.rb:7:in `(root)'

On a hunch, I decided to put the unjarred compass gem into my lib/ dir, which is accessible from where config.rb is. Then I added the following lines to config.rb:
# Looks like we need path to Compass too
$compass_path = File.join("..", "lib", "compass-0.12.1")

# Need to load Compass styling files
#load File.join(File.dirname(__FILE__), $compass_path, 'frameworks', 'compass')
#load File.join(File.dirname(__FILE__), $compass_path, 'frameworks', 'blueprint')

I ran ant again, and it worked! So basically I had to load in the actual compass stylesheets manually from config.rb. This means checking in more stuff to source control, but it works, and I can still exclude it from my app build. Would love to hear if there are better solutions out there.

axyl

unread,
May 18, 2012, 6:48:04 PM5/18/12
to compas...@googlegroups.com
Oops, those compass load calls should NOT be commented out!
Reply all
Reply to author
Forward
0 new messages