Amjath Sharief
Amjath Sharief

Reputation: 78

How to use both http server and application server in a java web application

I have some deployment model question for a Java EE web application. Currently we are deploying our web application as a WAR file in Tomcat 6. All the content is packaged with the WAR file including the static content like images, static html pages and so on. But i want to deploy these static content in a HTTP server and use the Application server only for retrieving the dynamic content. How do i split these things? Does any one has done any thing of this sort and have a good deployment model for my scenario. Help will be appreciated.

Is it a good idea to make 2 WAR files one with only static content and deploy that WAR in HTTP server and the rest as a different WAR file and deploy it in the Application server? But this approach will have impact on all the pages where the static content is currently referred and requires code changes which is very cumbersome since our project is Huge and the code based is very very big.

Any strategy and ideas are welcome.

Upvotes: 6

Views: 1895

Answers (3)

Florian Parain
Florian Parain

Reputation: 1099

This can be something interesting to do for performance reasons.

You should have separate deployment scripts / deployment files to do this. Having multiple file/WAR/folder/scripts to deploy for one project is not an issue. We have the same thing when you have to deploy your WAR and to update your database.

I would have a WAR file and a folder with your static content to deploy.


Edit

Deploying the static content in a HTTP server depends on the server. If you want to use Apache on a Linux server, you have to set up a Virtual Host.

<VirtualHost *:80>
  # This first-listed virtual host is also the default for *:80
  ServerName www.example.com
  DocumentRoot /www/domain
</VirtualHost>

In this example, you have the a virtual host that listens on 80 port, for any IP address and for the server name www.example.com. Then this is redirected to the /www/domain path.

You will find much more examples and configuration options in the documentation.

Upvotes: 1

f_puras
f_puras

Reputation: 2503

Up to version 4, Tomcat has been quite slow in serving static content. This is why it was frequently recommended to split dynamic from static content and serve the latter using a regular web server (the book you mentioned was issued in 2002...). Recent Tomcat versions do not face this problem, thus you can IMHO refrain from splitting, which can be a nightmare for both organization and security.

For static resources, you might rather focus on configuring proper caching, so they will not be transferred more often than necessary.

Upvotes: 0

Paulius Matulionis
Paulius Matulionis

Reputation: 23413

You can not deploy WAR file into HTTP server. A WAR is used for Java web applications it must be deployed into application server or servlet container (like Tomcat). I don't think that its a good idea to separate static content in a separate web application. If this is one project it should be one web application, besides:

A WAR file has a special folder structure and contains special files in addition to JSP pages, Java servlets, Java classes, HTML pages etc. which combined forms a Web Application.

You can hold your static contents in your one application and there is really nothing bad about it.

If your project is very huge and has a lot of files it is no problem, you just need to use the project structure like that, that it should be easily understandable and readable and the application server or servlet container will take care of deploying as many contents as there is.

Upvotes: 0

Related Questions