Maven + Spring MVC + JSP project, how to share view files?

Asked

Viewed 1,225 times

6

I’m trying to adjust a file structure to start a big project, an ERP to be more exact. Today, there is a good part of it made in PHP in a disorderly way. Let’s adopt Java Web (Maven + Spring MVC + JSP + Hibernate) to create the next modules and future remake the other modules. Within what has already been studied, I have a doubt, probably silly for you, but for me, I have not yet found the way.

We thought of creating a project for each module (system) only that there may be the possibility of a project having to use the resources of another project, in specific, parts of the view. How to control this view resource exchange?

I know Maven controls the dependencies and tals via multi-modules, but how would that matter of, for example, if I had a folder with images in Project A, and I needed to use them in Project B without having to give the full path?

thanks in advance.

2 answers

4


There are several ways to do this.

Putting resources inside a jar

Some frameworks (such as Primefaces and GWT) do this because it makes it easier to share static resources available on the classpath.

Create a Maven project to store these resources in java/main/resources. They go along with the system in a jar and can be served to the client through a Servlet.

Spring MVC already does this automatically with configuration:

<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/public-web-resources/"/>

See the documentation for more details.

War overlay

Another output is to create a web Maven project (WAR) with the general files and configure the Maven War Plugin of the other projects do overlay, merging the WAR’s.

This works because I’ve used it, but I confess that it can be confusing to set up and leave everything working perfectly, besides being more complicated to integrate with an IDE.

Resources outside the application

It is possible to configure a simple web server (as already mentioned in another answer) or in a separate Java web application.

You can use paths relative to the server root, for example: /resources-app/images/image01.png.

Obviously this can be a problem if you want to use different versions of projects using different Javascript’s, CSS’s and images.

Also, it may be a problem if the location of Resources is different. In this case, you can create a configuration on web.xml in each application with the base path of Resources. That way, simply change a single location to define whether the images will be in /app/imagens or http://192.162.0.1/images.

  • Thanks for the ideas utluiz and rdeandrade. I will try to see what I do and any later I put here the solution that was most appropriate to me.

1

What you can do in this case is a static file server and put it on an apache-only server. That’s common. But in the case if it is only HTML, CSS, JS, Images and etc. So in all the other modules you just need references the media server, which can even have the same DNS of the application server, being transparent when making the request.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.