Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
571 views
in Technique[技术] by (71.8m points)

webserver - How to deploy a spark Java web app?

I used spark web framework to create a webapp, but I don't know how to deploy this webapp. I'm sorry if this is very basic, but I'm new to spark framework and I cannot find any document that guide me how to deploy a spark webapp.:

  • How to deploy a spark webapp standalone
  • How to build a spark webapp (to war file or such a file) and deploy with web server (jetty or Tomcat).
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You will first need to create a regular Java project that can be built into a .war file (in Eclipse this would be a Dynamic Web Project)

The spark documentation at this link describes what needs to be added to your projects web.xml file. http://sparkjava.com/documentation.html#other-webserver

the param-value listed in the documentation within the filter needs to point to the class where you have defined your routes.

Additionally, all the code that was previously in main() needs to be moved to init().

@Override
public void init() {
    get(new Route("/test") {
        @Override
        public Object handle(Request request, Response response) {
            return "response goes here;
        }

    });

Also, in order for me to deploy it to JBoss, I had to only include the spark libraries and not the Jetty libraries. Once this was done, you should be able to build the war and deploy it to your server the same way you would any other Java project.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...