Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run a Java app on Apache 2.2 without Tomcat?

Tags:

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?

like image 478
nauten Avatar asked Jun 11 '13 00:06

nauten


People also ask

Can I run Java without Tomcat?

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.

Can we deploy Java application on Apache?

So the answer to your question is "you cant run it's only on Apache HTTP Server", because it's not a Servlet Container.

Is Apache 2.2 still supported?

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.


2 Answers

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.

like image 139
Barenca Avatar answered Oct 06 '22 23:10

Barenca


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.

like image 43
Marcelo Dias Avatar answered Oct 07 '22 01:10

Marcelo Dias