0

First post on here and I'm fairly new to JAVA so please keep that in mind ;) I've spent literally days trying to solve my problem and am running out of patience. Here's the deal : I've got a Spring Boot web app that I've successfully deployed on Digital Ocean by running a Tomcat Server and deploying a WAR file on my cloud VM. Everything was working fine with that set up when my app wasn't a Spring Boot app. Since then I've changed it to Spring Boot (added Spring Security etc.) and would like to deploy a JAR file which has Tomcat built into it which I was told is simpler and the better way of doing things. After creating my JAR file via my IntelliJ IDE, using Maven clean and build I'm able to run the app successfully on my windows machine command line which I've confirmed runs : localhost:8080/login spits out a message to the console so I know it's in my controller as well as I can see a connection to my DB. The issue is my JSPs files aren't loading and am seeing the below in my console:

Errors

Forwarding to [/WEB-INF/view/login.jsp] Completed 404 NOT_FOUND

After many hours I've realized that when I open my JAR file via WinRAR, the JAR file is missing my files that I had under my webapp directory in IntelliJ. Since this is a stand alone executable JAR, these files need to be located somewhere in my JAR, right?

Two questions I guess:

1.Do I need to do something special to get my webapp files added to the JAR during the build?

2.Can I just alter the JAR manually and place them in there? If so, where should I locate them so that they can be accessed and I won't get the 404 errors anymore?

Thanks all for your help. Much appreciated.

Zom8i3
  • 1
  • does [this answer](https://stackoverflow.com/questions/5013917/can-i-serve-jsps-from-inside-a-jar-in-lib-or-is-there-a-workaround) your question? – devReddit Aug 02 '21 at 18:10
  • 1
    As a note: If you're new, Thymeleaf is a much better option for writing your views than JSP. It more flexible, easier to test, and easier to work with. – chrylis -cautiouslyoptimistic- Aug 02 '21 at 18:11
  • To server JSP you need a war (the linked answer is for embedding jars with JPS in your application). JSP in a WAR with embedded tomcat can work but with limitations (which is also explained in the reference guide). – M. Deinum Aug 02 '21 at 18:16
  • Thanks for your input. So I changed my packaging to WAR from JAR, and ran the WAR by java -jar filename.war and it works like a WAR deployed on Tomcat Server. I guess I spent hours on something that wasn't possible - but now I know. So I guess then a JAR would work if I wanted to run a REST api without any views? Am I understanding that correctly? – Zom8i3 Aug 02 '21 at 19:16
  • Does this answer your question? [Can I serve JSPs from inside a JAR in lib, or is there a workaround?](https://stackoverflow.com/questions/5013917/can-i-serve-jsps-from-inside-a-jar-in-lib-or-is-there-a-workaround) – pringi Aug 03 '21 at 09:32

0 Answers0