views:

729

answers:

3

Hi,

How can I serve some static content in liferay? I have a directory structure with htmls, css, etc and I would like to serve it with an address like http://localhost:8080/myStaticContent/index.html and so on.

I don't want to use a front-end http server like apache.

+1  A: 

I assume Liferay is using JBoss or Tomcat in this case. Try this:

  • find server.xml and add a <Context> element to it, if it is jBoss, you can find server.xml here:

[jboss-home]/server/[config-name]/deploy/jboss-web.deployer/server.xml

<Context path="/myStaticContent" 
    docBase="/absolute/path/to/static/content" debug="0" reloadable="true"/>

It goes within the "Host" element like this:

<Host name="localhost" .....> <!-- add it here --> </Host>
  • in the location mentioned for docBase ("/absolute/path/to/static/content") add a WEB-INF folder and place a bare-bones web.xml inside it.
Peter Thomas
A: 

Edit: I think I've misread your question when answering this - I'll leave the answer here just in case somebody else finds this question and has some static content requirements different from yours. Peter and Miguel give answers that better match your specific question)


An easy way might be to leverage liferays cdn features (cdn="Content Delivery Network"). Unfortunately - on a quick scan through the documentation - I've only found this configuration option but missed some information about what content is considered "static". That's not to say that the information isn't there - I just didn't find it.

I guess that - even though a cdn implies a different hostname - you might get away with the same host name and possibly another webapplication context path (e.g. the path on your server). You can deploy any number of independent applications within the server serving liferay.

Especially when you want to single out static content to a different host/application, you might be better of with a dedicated server (or at least dns name) or the apache/tomcat conbination, as apache reportedly serves static content with a lot less resources than tomcat does.

Olaf
+1  A: 

I've done it by deploying a .war with only static content. The path is the liferay url/war_name.

So if I have a war with a file like this:

myproj.war
+-- myDir
     +-- myFile.html

The url will be something like http://localhost:8080/myproj/myDir/myFile.html

Miguel Ping
you can also go without myDir - shortening the URL. I'm not sure if a war file with static content also requires a WEB-INF/web.xml to be picked up by a servlet container, even if there's no servlet contained.
Olaf
ok - having commented this I see that you answered your own question. Never mind. For those also trying this: note that liferay serves some URLs that are not immediately obvious, such as /c/* /html/* /images/* and some more. It's easy to get naming conflicts here.
Olaf
Thanks for the comments
Miguel Ping