I'm building a webservice with Java that does not use JSP or servlets, and want to run it on my Apache HTTP server without having to install and configure Tomcat. Is this possible (easily), and how can I go about it?
I've been searching for information on this and the only thing I've come across is the mod_jk Tomcat connector which still requires Tomcat to be installed. Am I missing something?
Java SE – A platform for applications that don't use a web container, or use one other than Tomcat, such as Jetty or GlassFish. You can include any library Java Archives (JARs) used by your application in the source bundle that you deploy to Elastic Beanstalk.
So the answer to your question is "you cant run it's only on Apache HTTP Server", because it's not a Servlet Container.
Apache httpd 2.2 End-of-Life 2018-01-01 As previously announced, the Apache HTTP Server Project has discontinued all development and patch review of the 2.2.
Of course It is possible. You could do It using mod_cgi.
A very simple example would be like this:
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello Java CGI world!");
}
}
and then a script file (HelloWorld.shtml -do not forget the execute permission) that executes the Java class
#!/bin/bash
echo "Content-type: text/html"
echo ""
/usr/bin/java HelloWorld
In Apache conf, just define your script directory, something like this:
ScriptAlias /cgi-bin/ /Users/hectorsuarez/Proyectos/test/cgi-bin/
<Directory "/Users/hectorsuarez/Proyectos/test/cgi-bin">
SetHandler cgi-script
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
That's it!. This is a very simple and trivial example.
This will get complicated because you could probably need a template engine and a much better way to manage the incoming CGI calls. But yes, It is possible.
First of all, Servlets is the very basics of Java for Web development. So, whatever web development you are doing, like Web Services, you'll need a Servlet Container, as Tomcat.
So the answer to your question is "you cant run it's only on Apache HTTP Server", because it's not a Servlet Container.
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