2

My Package-Structure looks like:

  • src/main/java
  • src/main/resources
  • src/test/java
  • src/test/resources
  • src/main/webapp/css
  • src/main/webapp/images
  • src/main/js
  • src/main/WEB-INF

My images are stored under src/main/webapp/images.

Now i want to dynamically link to a picture e.g.:

    Image picture = new Image("picture",
                    new ContextRelativeResource("/images/races/"
                            + dynamicPicture));

The Problem is, that my Application can't find /images/races/$dynamicPicture. How do i set the correct path to my image folder? The Appliation Server used is Jetty.

lazydaemon
  • 2,429
  • 2
  • 17
  • 12

2 Answers2

1

Indeed, your code should work. Are you using Maven to manage your project and to start Jetty?

Andrea Del Bene
  • 2,521
  • 1
  • 15
  • 20
  • I use maven to manage my project. To deploy my project, i run "Run as -> Maven Install". Then i copy the .war File to my webapps Folder in the Jetty Directory. – lazydaemon Aug 20 '12 at 18:53
  • Now i copied all the images into the specific package of my Java-Class and .html file and implemented the image with: new Image("image", new PackageResourceReference(MyPage.class, picture + ".gif")); It's not what i wanted but it works. – lazydaemon Aug 20 '12 at 19:54
  • 1
    Try by removing the leading slash from "/images/races". I also think that it should work. You can simplify it a bit by using ContextImage component. – martin-g Aug 21 '12 at 14:29
  • @martin-g How can this be the solution? ContextRelativeResource checks whether there's a leading slash and adds one if it's omitted (1.5.7). – Christoph Leiter Aug 22 '12 at 12:19
0

It will work with (removed the leading slash)

    Image picture = new Image("picture",
                new ContextRelativeResource("images/races/"
                        + dynamicPicture));
lazydaemon
  • 2,429
  • 2
  • 17
  • 12