Is XSLT considered source or resource?

Hello, I’m Cliff you friendly neighborhood XML fanatic / Maven2 evangelist / Groovy sportsman / insert ridiculous label here. Today’s topic is a dilemma regarding where XSLT files should be placed in a Maven2 project. Because I’m still brand new to Maven and its philosophies and such I continue to have questions like “Where do I put X file?” Also, because I’m too arrogant to admit my lack of knowledge I present these questions to you as dilemmas that we solve together (that is you give me the answer I feel important because I raised the topic.) rather than in their true interrogative form. As I was saying my question… ahem! My topic is the location of XSLT source in a Maven2 project. the twist involves how the source is tested in a unit test. In other words how does the build system make the templates available for execution, or even simpler, how do you run the dang XSLTs? My initial instinct is to place them under src/main/xsl because why? They’re source files, that’s why! I then instinctively tag them as source files in Idea, my java editor of choice. But, and there’ always a but, they can not be executed if they are placed under the src umbrella because I don’t compile them. That means they don’t end up under the target folder where all of the executable goodies go.

My next natural instinct is to place them under src/main/resources. I want to do that because it makes my life easier. Everything under the resources folder is copied over to the target folder by the build system which makes them available for execution by whatever code I choosed to use for execution. But (didn’t I say there would always be a but?) that doesn’t feel right because I view the stylesheets as source code not as a resource and as such it ought to be given its rightful home under /src/main! (A little home with its name, xsl, on the front door so we can, like, always find it. ) A comprimise would be to just compile the dang things so they can exist under src as source code but I just don’t feel like being bothered with compiling them. It’s too big a hassle especially with Maven not handling XSL compiles by default. Then I feel bad when I think that way. What if someone decided to lump you in some general category just because they didn’t feel like dealing with you? You would feel just as lost and neglected as my XSL stylesheets now wouldn’t you? Why do I make life so much more difficult than it needs to be? Holla at me people…

(I know I promised to come up with something different and more clever than “holla at me”. However right now I’m drained of creativity so gimme a break. So gimme a shout, help me Git-R-Done, dice que pasa, or whatever it takes to get some good ideas rolling. Thanx in advance for the feedback or lack thereof…)

2 thoughts on “Is XSLT considered source or resource?

  1. I believe the common practice is to place the XSL files into src/main/resources, and access them via:

    String xslPath = MyClass.class.getResource(“/template.xsl”).toExternalForm();

    ( or this.getClass().getResource(“/template.xsl”).toExternalForm(); )

    I feel that anything that gets applied at runtime is a resource and thus should end up in the resources directory. Additionally, if you were compiling the XSL into translets, I’d agree with you that the Java source should go into src/main/java.

    If you’re not happy with lumping all of your resources together, just add a new subdirectory and place them in src/main/resources/XSL:

    String xslPath = MyClass.class.getResource(“/XSL/template.xsl”).toExternalForm();

  2. That’s how I’m treating my XSLT files now. I put them into the resources folder, but it just doesn’t feel right because it’s programming sources not resources. That’s why I had the brilliant idea about compiling to translets. If I did that I would want to put them under src/xsl. Thanx Chuck.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s