开发者

Java libraries to manage CSS explosion and or reuse?

开发者 https://www.devze.com 2023-01-16 02:43 出处:网络
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.

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 u开发者_StackOverflow中文版sing 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?


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.


I ended up using wro4j.

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


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


The Sass command-line interface is very thorough. If you call out to sass --update in your build rules, you can just use the standard Sass executable (either via Ruby or JRuby) without having to integrate it directly into your build.

0

精彩评论

暂无评论...
验证码 换一张
取 消