How to configure static resources in jBoss AS 7
Asked Answered
V

2

10

I'd like to upload images to the server, store them in file system (outside server) and then display them on my JSF page.

I'd like to find something like this:

<?xml version="1.0" encoding="UTF-8"?>
<Context allowLinking="true" cookies="true" crossContext="true" override="true">
    <Resources allowLinking="true"
        className="com.triplemind.site.engine.SourceResolverContext"
        homeDir="/home/myapp/files" />
</Context>   

I found some solutions, but I wonder if there is a better way to do this.

  1. Configure static resources in JBOSS AS 7 (not answered)
  2. Replacement for context.xml in AS7? Access files outside the WAR? (not answered)

There are jBoss documentation I've found:

  1. The static-resources element
  2. AdminGuide Container Configuration

Any help will be appreciated. Thanks in advance

Vazquez answered 20/12, 2011 at 13:9 Comment(0)
V
3

Finally, I've decided to use FileServlet implemented by BalusC (link). This solution suits me for now. I've only changed its basePath to some certain path on my server.

Vazquez answered 14/1, 2012 at 0:3 Comment(1)
What happened to Convention over configuration?Griggs
A
1

This method documented on the JBoss forums works for us in loading all the static resources from an exploded folder - which has to sit within JBOSS_HOME but at least not packaged in EAR/WAR.

https://community.jboss.org/wiki/HowToPutAnExternalFileInTheClasspath

I had to create a module folder called com/mycompany/main and add all the images in there.

Skip step 3 and use step 4 instead. (Manifest.MF entry - which works)

The image is now loaded using

URL imgUrl = this.getClass().getClassLoader().getResource("myimage.jpg");

Andi answered 5/11, 2012 at 5:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.