how to create a war file and deploy it on Tomcat or any server that works with Spark?

2,507 views
Skip to first unread message

IVYtony smth

unread,
May 29, 2014, 11:09:30 PM5/29/14
to spar...@googlegroups.com
I am new when it comes to web development using Java and Tomcat. So I've created a simple website using Spark framework and ORMLite/MySQL. I have only one controller class that serves all requests for urls.

When testing my website in IntelliJ, I put all the get() and post() inside of main(){}, but from my reading of some scattered help on the internet, I put all my get() and post() methods inside of public void init() { }. In addition, I created a web.xml in the resources directory, and the following is the content of my web.xml:

<filter>
    <filter-name>SparkFilter</filter-name>
    <filter-class>spark.servlet.SparkFilter</filter-class>
    <init-param>
        <param-name>applicationClass</param-name>
        <param-value>controller.AdminInitController</param-value>
    </init-param>
</filter>
<filter-mapping>
<filter-name>SparkFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>



I am not sure how to create a war or jar file out of my source code and how to deploy it on a server (either Tomcat or anything else that works for Spark). I will appreciate your help. Thanks

Tony


Per Wendel

unread,
May 30, 2014, 6:29:42 AM5/30/14
to spar...@googlegroups.com
Are you sure you don't want to run Spark the intended way with the Embedded jetty? Then you don't need a web.xml and an init method. You just have a main and Spark will automatically start a jetty in the background.

Br,
Per

Paul Kavanagh

unread,
Dec 22, 2014, 7:10:25 PM12/22/14
to spar...@googlegroups.com
Per, when you say that the intended way to run Spark is with the embedded Jetty are you saying that it doesn't work with other servers like Tomcat and Glassfish? There are legitimate reasons for people to do this in production systems.

On this Google Group and in the documentation, there is no example of a working implementation with an external server. And questions on how to do it get answered like this...

Leonan Luppi

unread,
Dec 23, 2014, 7:10:29 AM12/23/14
to spar...@googlegroups.com
Hello,


I create an example to show

Paul Kavanagh

unread,
Dec 23, 2014, 4:17:10 PM12/23/14
to spar...@googlegroups.com
OK, I am going to try to copy this exactly.

Which version of Eclipse? Luna 4.4?

What are you using to add Gradle support? The Pivotal plugin for 4.4 is broken

What Tomcat version? 

Leonan Luppi

unread,
Dec 23, 2014, 4:59:02 PM12/23/14
to spar...@googlegroups.com
Yeah,

I'm using Eclipse Luna 4.4

For Gradle you need download and use, visit: https://www.gradle.org/ 

It's Tomcat 7

Paul Kavanagh

unread,
Dec 23, 2014, 5:40:29 PM12/23/14
to spar...@googlegroups.com
OK. I have built it. It builds OK and creates a jar.

Now what do I do? Tomcat wants a war, not a jar. How do you deploy?

Leonan Luppi

unread,
Dec 23, 2014, 5:51:24 PM12/23/14
to spar...@googlegroups.com
See your personal e-mail buddy.

To build you need to build with maven, ant, gradle. Just see google: how to create .war package with maven/ant/gradle

Paul Kavanagh

unread,
Jan 1, 2015, 6:23:59 PM1/1/15
to spar...@googlegroups.com
Your example does not address my issue. My original example built a WAR file with Gradle. But it doesn't run when deployed to Tomcat.

Paul Kavanagh

unread,
Jan 4, 2015, 5:16:11 PM1/4/15
to spar...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages