-1

Background

I am using a Java application that starts, runs, produces data continuously for a long period (i.e., hours), and shuts down only when explicitly instructed to do so. It has a Java-based GUI that appears on the machine where the application runs. The GUI is very difficult to extend for my purposes, and not useful if I run the application on a headless remote server. I would like to construct a web interface for this application where users can request data from the running application, visualize retrieved data, and send commands to change the operation of the application. AJAX requests from a browser to the application will suffice for my purposes. I have investigated how to do this, and all solutions seem to require heavy-duty, external server setup (e.g., Tomcat) or start-from-scratch (e.g., socket) development. This seems absurd given the conceptual simplicity of the task: all I need to do is respond to an HTTP request. There has to be something simpler and lighter weight than these approaches, especially because I'm prototyping. What's the simplest option?

Question

What is the simplest way to respond to AJAX in an existing Java application without setting up an external server?

Dylan Knowles
  • 2,726
  • 1
  • 26
  • 52

2 Answers2

1

You'll want to create an integrated http server (it's the only way to do it) but you can use something like Jetty that should be lightweight and quick to manage.

The answer by Kris in the following question should help you:

Create a simple HTTP server with Java?

Here is the as of current documentation for embedding Jetty

(Credit to Dylan Knowles)

Community
  • 1
  • 1
jconder
  • 686
  • 4
  • 9
  • Perfect! I hadn't seen that. After a bit of sleuthing [I found the current documentation for embedding Jetty](http://www.eclipse.org/jetty/documentation/current/advanced-embedding.html), which seems to be exactly what I need. Can you put that in your answer as well for completeness? – Dylan Knowles Nov 19 '15 at 22:59
0

I know this question has already been answered, but I have had very good luck with Spring Boot.

hooknc
  • 4,854
  • 5
  • 31
  • 60