0

I have a folder structure like so:

project/src/main/
  java/apps/
    blog/
      controllers/
        blogController.java
      models/
        post.java
      views/

  webapp/WEB-INF/views/
    blog/
      blog.jsp

I want to move the blog.jsp from the WEB-INF/views directory to the apps/blog/views/ directory to allow for more easily porting code from one spring MVC application to another.

I have tried to create my own view resolver but the resolver seems to only resolve to paths within the webapp directory.

I thought I could use maven to collect the jsp's into the /WEB-INF/views/blog/ on a maven goal but I can't seem to find clear instructions to get the views in the views folder under the correlating app name (views/blog)

Is it possible to have this kind of setup or is there a better way to achieve this?

Archangel33
  • 496
  • 8
  • 22
  • Please refer http://stackoverflow.com/questions/22084623/how-do-i-move-my-src-main-webapp-web-inf-views-folder-out-of-src-main-webapp – shankarsh15 May 19 '16 at 14:47

1 Answers1

0

Based on your description (and default maven behavior), the contents of webapp are actually in the root of the WAR that gets built. So any views you want should be within there at least. You can get maven to customize the path of /src/main/webapp if that's what you are looking for.

As for the location of the views within the WAR, I also don't like them inside WEB-INF. I do the following (note there are many variations of view resolvers...)

    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setViewClass(JstlView.class);
    viewResolver.setPrefix("/views/");
    viewResolver.setSuffix(".jsp");
    viewResolver.setExposeContextBeansAsAttributes(true);
    return viewResolver;

The code above allows me to have a view like /src/main/webapp/views/blogs/blog.jsp and reference it by the string "blogs/blog"

Adam Erstelle
  • 2,454
  • 3
  • 21
  • 35
  • This doesn't really allow me to move the views into the apps `views` directory... can I get maven to copy all jsp's in the project and place them in the war's root, on build? such as an include statement of some kind? – Archangel33 May 19 '16 at 15:03