Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java libraries to manage CSS explosion and or reuse?

Java Q: I like CSS for simple web pages but loathe it when it comes to real world sites because you get css explosion and lots of repeating.

I am tempted to use Sass and or Compass but they are Ruby programs which will most likely require some interesting Maven + JRuby love to get working for Java Web app dev. This also makes it difficult if you are using Eclipse or any IDE that supports synchronization with a running web app.

Is there a better alternative for the hell that is CSS in the hell that is Java?

like image 898
Adam Gent Avatar asked Sep 10 '10 00:09

Adam Gent


3 Answers

I went down the same road recently using LessCss, a similar technology. At first I tried to embed JRuby in my build lifecycle. But unfortunately Maven + JRuby is a monster, it's slow, huge and buggy (half the time it wouldn't even start because it would complain about the file path it was running on).

Fortunately, there is now a JavaScript port of LessCss, which I now embed via Mozilla Rhino. I describe the process in this blog post.

Yesterday though I took it to the next level, making a Maven LessCss Plugin to minimize POM configuration and code duplication. Unfortunately I can't share it because it's proprietary code for my current client, but the solution is simple:

Use GMaven to create the Plugin, create an abstract base mojo that calls the LessCss compiler and several concrete implementations that configure the base mojo for different resource sets:

e.g.

  • lesscss:compile
    compiles from all <resources> to ${project.build.outputDirectory}
  • lesscss:test-compile
    compiles from all <testResources> to ${project.build.testOutputDirectory}
  • lesscss:war-compile
    (compiles from all src/main/webapp to ${project.build.directory}/${project.build.finalName} , the exploded war directory)

So while I can't help you with SASS (apart from you asking the auth or to port it to Groovy, Java or JavaScript), I think I've shown you a feasible alternative.

Of course you can also implement a Maven Plugin in java without Groovy (also embedding the JavaScript via Rhino), but I think it's easier in Groovy.

like image 82
Sean Patrick Floyd Avatar answered Nov 16 '22 16:11

Sean Patrick Floyd


I ended up using wro4j.

Highly recommend the library as it will handle many things like less css and coffee CoffeeScript.

like image 3
Adam Gent Avatar answered Nov 16 '22 18:11

Adam Gent


A good solution for using sass with eclipse is answered in this question.

like image 1
Joep Avatar answered Nov 16 '22 18:11

Joep