Search code examples
javatomcatspark-javaj2html

Can I use Java Spark Framework to create regular War for deploying in Tomcat


I have happily used Java Spark Framework (& j2html) as part of a standard Java application to provide a browser based UI, this has worked very well.

I would now like to build my website using the same technology instead of using Servlet/Jsps as I am currently. But the difference is that the website runs on AWS within a Tomcat container and Im not sure if Java Spark can be used to create a web archive (.war) file so I can continue to deploy it in the same way.


Solution

  • It is not difficult.

    From their documentation:

    1. You need to change your main class and implement spark.servlet.SparkApplication
    2. Add the specified filter to your web.xml changing <param-value>com.company.YourApplication</param-value> with the name of your class.
    3. Move your routes to the init method of your main class.

    Hope this helps.