Question

I'm working on a website running in Tomcat that stores a lot of member data, and I'm not sure how to best package it.

I want to be able to deploy a war easily without needing to remove anything from it first.

My first thought was to break out the member data into its own directory outside of the war, but my problem is that some of that content needs to be linked in the website (images, etc).

There has to be a better solution than deploying a war, then copying back the data. Does anyone have any suggestions?

Was it helpful?

Solution

Your first thought was correct. Storing data in outside direcotry is best solution. You can easily fix problem with images by creating servlet that would access that outside directory on image request.

I can't post my code, but here is similar snippet that creates response. You just have to create class extending FileServlet and write code to load file from your directory.

http://snippets.dzone.com/posts/show/4629

Then, add this to your web.xml:

<servlet>
    <servlet-name>My File Servlet</servlet-name>
    <servlet-class>my.package.FileServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>My File Servlet</servlet-name>
    <url-pattern>/upload/*</url-pattern>
</servlet-mapping>

and every link like http://myapp.com/upload/userimage.jpg will be created by servlet

OTHER TIPS

You should definitely separate your data from your application. As I am unsure on the reasons you originally had for putting member data (apparently images and something else) I can offer suggestions based on a more ideal environment.

If you are storing information on a lot of different people and need access to it in multiple places, why wouldn't you choose to use a database? Perhaps even a free one like PostgreSQL or MySQL?

If you store your data in a database it is easy to retrieve through java, either use a ORM like Hibernate or just some basic JDBC libraries. This assumes you understand SQL and the database layer in Java.

Then if you need access to certain files you can either create a Service Orientated Architecture (SOA) and use a restful web service to pull the images based off a url. This would allow storage to be offloaded to another machine in your trust zone.

It is hard to offer a good solution without more details on the problem and your server setup.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top