With this link, I made rest api server. It works well when I run on eclipse ide. However, I don't know how to deploy on server. I made war file and tried to deploy on tomcat, but somehow cannot access any page that I defined, unlike running on eclipse. Here is some gradle configuration that I made.
apply plugin: 'war'
war {
baseName = 'server'
manifest {
attributes 'Implementation-Title': 'SparkAPIServer', 'Implementation-Version': '1.0', 'Main-Class': 'com.server.Main'
}
}
I'm sure that 'Main-Class' path is correct. Any idea of this?
Running from Eclipse IDE is not the same like running on Tomcat, because when running on Eclipse Spark uses the built-in Jetty server, and when deployed to Tomcat Spark runs on Tomcat server.
Quoting from the documentation:
Other web server
To run Spark on a web server (instead of the embedded jetty server), an implementation of the interface spark.servlet.SparkApplication is needed. You have to initialize the routes in the init() method, and the following filter has to be configured in your web.xml:
...
So in order to run the same code after deployed to Tomcat, you need to:
Seeing that you use Spark and a main method to start a webserver, you are looking actually to create a jar, like the following (adapt as needed):
jar {
manifest {
attributes 'Main-Class': 'com.foo.bar.MainClass'
}
}
See the jar task documentation. And don't forget to add the classpath for your external libraries into the manifest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With