Hi,

CssResoourceReference uses the passed Class as a scope, i.e. it is
something like
TheClass.class.getResourceAsStream("theNameOfTheResource.css").
If you put your .css file at src/main/resources/ then at runtime it is at
the root of the classpath. I.e. to load it you need to use TheClass.class.
*getClassLoader()*.getResourceAsStream("theNameOfTheResource.css").
Wicket doesn't provide out of the box ResourceReference that loads from the
classpath root, mainly because we recommend to organize your resources to
reside close to the component(s) which use them.

Quick solution for you is to
use org.apache.wicket.request.resource.MetaInfStaticResourceReference and
move your .css file at src/main/resources/META-INF/resources/.
/META-INF/resources/ is a special place for resources defined in Servlet
3.0 specification. That's why it is supported in Wicket.

Have fun!


Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Thu, Apr 14, 2016 at 7:40 PM, Lon Varscsak <lon.varsc...@gmail.com>
wrote:

> Hey guys,
>
> I’m new here and I’m trying to get a URL for a resource (css) located in
> /src/main/resources/.  I can across CssResourceReference, but if I use
> “resources/whatever.css” or “/resources/whatever.css” the file isn’t
> found.  If I use "../../../../whatever.css” it works.  I’m assuming because
> it’s located in the default package I’ve got to drop down into that.  Is
> there 1) a better way to do this? or 2) a way to do it that’s more
> predictable, like something that says start at the root package?
>
> Thanks for any insights!
>
> -Lon
>
> P.S. — I’m not deploying with a war, but as a jar with embedded Jetty.
>

Reply via email to