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

6

I'm trying to fit a file structure to get a big project, an ERP to be more accurate. Today, there is a good deal of it made in PHP in a messy way. Let's take Java Web (Maven + Spring MVC + JSP + Hibernate) to create the next modules and in the future redo the other modules. In what has already been studied, I have a doubt, probably silly for you, but for me, I still have not found the way.

We think of creating a project for each module (system) only that there may be a possibility that one project has to use the resources of another project, in particular, parts of the view. How can I control this view resource swap?

I know that Maven controls multi-modules dependencies and tals, but how would that be the question of, for example, if I have a folder with images in project A, and I need to use them in project B without needing to tell the full path?

Thank you in advance.

    
asked by anonymous 03.07.2014 / 18:37

2 answers

4

There are several ways to do this.

Placing resources inside a jar

Some frameworks (such as PrimeFaces and GWT) do this because it makes it easier to share static resources available in 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 via a Servlet.

Spring MVC already does this automatically with the configuration:

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

See the documentation for more details.

War overlay

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

This works because I've used it, but I confess it can be a bit confusing to configure and make everything work perfectly, and it's more complicated to integrate with an IDE.

Out-of-application features

You can set up a simple web server (as already mentioned in another answer ) or in a Java web application separated.

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

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

In addition, it can be a problem if the location of the resources is different. In this case, you can create a setting in web.xml in each application with the base path of the resources. That way, just change a simple location to define whether the images will be in /app/imagens or http://192.162.0.1/images .

    
03.07.2014 / 20:29
1

What you can do in case, is a served from static files and put it on a server only with apache same. This is common. But in case if it is only HTML, CSS, JS, Images and etc. So in all other modules you just have references to the media server, which can even have the same DNS server as the application, transparent at the time of request.

    
03.07.2014 / 19:03