0

I am trying to create a maven spring boot application to be deployed in Tomcat. I am following what is suggested in Spring docs and other stackoverflow suggestions- war, Application.java extending SpringBootServletInitializer, removing spring-boot-maven-plugin from build plugins etc. War file is generated and is deployed in tomcat. But what I found is all static files are packaged under /WEB-INF/classes folder and I am not able to access the page. My project structure is as below:

structure

Can anybody tell me how I can package the war properly to be deployed in Tomcat.

kryger
  • 12,906
  • 8
  • 44
  • 65
smj100
  • 15
  • 6

2 Answers2

2

That doesn't change anything.

If you put your static assets in src/main/resources/static (and they end up in WEB-INF/classes/static), Spring Boot will serve them properly. So a src/main/resources/static/foo.png will be available at http://localhost:8080/your-context/foo.png if the context of your webapp is your-context.

Regarding the configuration, you can also go on start.spring.io, click advanced and chose war and you'll get an empty project pre-configured.

Or you can click this: https://start.spring.io/#!packaging=war

Stephane Nicoll
  • 31,977
  • 9
  • 97
  • 89
  • I have tried adding static resources in static but in wain. In fact /static (or /public or /resources or /META-INF/resources is ok as per spring docs. [link](http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html) – smj100 Feb 09 '16 at 17:30
  • are you trying to access that home.html thing? That must be in `src/main/resources/static/index.html`. – Stephane Nicoll Feb 09 '16 at 17:41
  • Yes Stephane, I want to package the contents of src/main/resources/static folder in the context path when I build the war in Tomcat. I am looking for a way to package the contents of static folder to context path, like traditional web applications. – smj100 Feb 10 '16 at 03:16
  • I am sorry to disappoint you but there's is nothing to do, really. Perhaps I don't understand what you're trying to do? I've created [a simple application](https://github.com/snicoll-scratches/test-war-static) that showcases what I mean. Check [the commit](https://github.com/snicoll-scratches/test-war-static/commit/56a9088cf40d0fef81fa04f2c36c3502958f4f70) for more details. – Stephane Nicoll Feb 10 '16 at 07:12
  • I have deployed the sample application without making any change to my tomcat 8 server, but I am not able to make it , I am not sure why. – smj100 Feb 10 '16 at 08:12
  • I am sorry, I went as far as I could. – Stephane Nicoll Feb 10 '16 at 08:16
  • Fine no problem.. one last question ..Do I have to change any tomcat settings? – smj100 Feb 10 '16 at 08:35
  • Nope. To test this I just downloaded tomcat, unzip, copy the war to webapps and run it. And it worked so I have no idea why it does not work for you. – Stephane Nicoll Feb 10 '16 at 08:39
  • I solved the issue .. it's because java compilation version. I build the project using java 1,8, but my tomcat was running on JRE -7. Finally it worked .. Thanks for your help – smj100 Feb 10 '16 at 13:59
0

The issue is because of version issue. I compiled the application with Java 8 and deployed it in tomcat running under JRE 7. It may help someone facing the same issue. I got the clue from the below post: Spring boot war file deploy on Tomcat.

Community
  • 1
  • 1
smj100
  • 15
  • 6