Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6717221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:49:37+00:00 2026-05-26T08:49:37+00:00

Im working on a web app where we keep the code and web resources

  • 0

Im working on a web app where we keep the code and web resources (such as css, image files etc) separated.

I have a file located here:

project root/src/main/webapp/images/icons/16/add.png

And in this location:

project root/src/main/java/se/su/dsv/scipro/icons

I have a class like so:

package se.su.dsv.scipro.icons;

import org.apache.wicket.ResourceReference;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.model.Model;


public class ImageIcon extends Image {

    private static final long serialVersionUID = 1L;

    public static final String ICON_NEW_ADD = "../../../../../../webapp/images/icons/16/add.png";

    public ImageIcon(String id, String name, String size, String alt){
        super(id, new ResourceReference(ImageIcon.class, name));
        if(alt != null){
            add(new AttributeAppender("alt", true, new Model<String>(alt), " "));
        }
        else {
            add(new AttributeAppender("alt", true, new Model<String>(name), " "));
        }
    }

    public ImageIcon(String id, String name){
        this(id, name, "", null);
    }

    public ImageIcon(String id, String name, String alt){
        this(id, name, "", alt);
    }

    public static ResourceReference getImage(String imageName, String imageSize){
        return new ResourceReference(ImageIcon.class, imageName);
    }
}

But when I use this class somewhere in a panel or a page, e.g. like this:

add(new ImageIcon("new_add", ImageIcon.ICON_NEW_ADD));

I get the following exception:

2011 Oct 18 11:11:17,947[ERROR] - RequestCycle - Can't instantiate page using constructor public se.su.dsv.scipro.basepages.DemoPage(org.apache.wicket.PageParameters) and argument 
org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor public se.su.dsv.scipro.basepages.DemoPage(org.apache.wicket.PageParameters) and argument 
    at org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:212)
    at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:65)
    at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:298)
    at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:320)
    at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:234)
    at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
        at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
    at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
    at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1436)
    at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
    at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
    at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:319)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:188)
    ... 27 more
Caused by: java.lang.IllegalArgumentException: Invalid path ../../../../../../webapp/images/icons/16/add.png
    at org.apache.wicket.util.lang.Packages.absolutePath(Packages.java:105)
    at org.apache.wicket.util.lang.Packages.absolutePath(Packages.java:44)
    at org.apache.wicket.markup.html.PackageResource.<init>(PackageResource.java:504)
    at org.apache.wicket.markup.html.PackageResource.newPackageResource(PackageResource.java:448)
    at org.apache.wicket.markup.html.PackageResource.get(PackageResource.java:424)
    at org.apache.wicket.ResourceReference.newResource(ResourceReference.java:304)
    at org.apache.wicket.ResourceReference.bind(ResourceReference.java:151)
    at org.apache.wicket.markup.html.image.resource.LocalizedImageResource.bind(LocalizedImageResource.java:180)
    at org.apache.wicket.markup.html.image.resource.LocalizedImageResource.setResourceReference(LocalizedImageResource.java:246)
    at org.apache.wicket.markup.html.image.Image.setImageResourceReference(Image.java:178)
    at org.apache.wicket.markup.html.image.Image.<init>(Image.java:101)
    at org.apache.wicket.markup.html.image.Image.<init>(Image.java:77)
    at se.su.dsv.scipro.icons.ImageIcon.<init>(ImageIcon.java:83)
    at se.su.dsv.scipro.icons.ImageIcon.<init>(ImageIcon.java:93)
    at se.su.dsv.scipro.basepages.DemoPage.<init>(DemoPage.java:16)
    ... 32 more

I guess it is because the image file resides outside any Java package? How can I address this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:49:38+00:00Added an answer on May 26, 2026 at 8:49 am

    Use a ContextRelativeResource. With it, the path to the image will be considered relative to the context root.

    For instance, if you’d show this image with the following HTML:

    <img src="images/icons/16/add.png">
    

    Use the following:

    new Image("add", new ContextRelativeResource("/images/icons/16/add.png")))
    

    You might also find this blog post useful.

    There’s no ResourceReference version of this variant that I’m aware of, although you can try to integrate the one attached in this JIRA issue: WICKET-790

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a web app using C# and asp.net I have been
I'm working on a web.py app for uploading files and im having real problems
we're working on a web app with Spring, Hibernate/JPA and Maven. We have several
I am working on a web app that uses Perl and I need to
I'm working on a web app that is somewhere between an email service and
I'm working on a web app project (in java; not that it matters) and
I'm working on a web app which is heavy on the client side, which
I am working on a web app which makes use of a 3rd party
I'm working on a web app and I need to get a div to
I'm working on a web app for my company that will let us do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.