Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Any way to invoke java program directly under CGI?

Reply
Thread Tools

Any way to invoke java program directly under CGI?

 
 
RobertMaas@YahooGroups.Com
Guest
Posts: n/a
 
      09-01-2003
Let's say I have written a "Hello World" java program: h.java
and I've compiled it to: h.class
It emits a HTTP header line, a blank line, then the "Hello World!" line.
Is there any way to directly run that as a CGI script, or do I have to
use a shell script that calls java indirectly?

For example, in PERL, I can make a CGI PERL script directly, like this:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, world!\n";
(That's what I have in http://www.rawbw.com/~rem/cgi-bin/h-perl.cgi now.)

and likewise I can make direct scripts in sh:
#! /bin/sh
echo 'Content-type: text/html'
echo
echo 'Hello World!'
(That's what I have in http://www.rawbw.com/~rem/cgi-bin/h-sh.cgi now.)

But in CMUCL, I have to
make a sh script that indirectly invokes CMUCL, like this:
#! /bin/sh
/usr/local/bin/lisp -eval '(progn (format t "Content-type: text/html~%~%Hello World!~%") (quit))'
(That's what I have in http://www.rawbw.com/~rem/cgi-bin/h-cmucl.cgi now.)

So if my Hello World program is written in java, can I do it directly
like this:
#! /usr/local/jdk1.2.2/bin/java
something... h.class ...something

or do I have to do it indirectly via sh script like this:
#! /bin/sh
/usr/local/jdk1.2.2/bin/java h
(That's what I have in http://www.rawbw.com/~rem/cgi-bin/h-java.cgi now.)

 
Reply With Quote
 
 
 
 
Chris Uppal
Guest
Posts: n/a
 
      09-02-2003
LDV wrote:

> > Is there any way to directly run that as a CGI script, or do I have
> > to
> > use a shell script that calls java indirectly?

>
> To run your Java CGI directly, you have to use a binary
> wrapper/launcher (painfully slow) or compile it to a native binary
> using GCJ (available now) or Excelsior JET (Linux version is coming
> soon):


If the CGI program does a small enough amount of work for the JVM startup time
to be significant, then it'd be worthwhile trying to run it in pure interpreted
mode (if your particular JVM supports it) or perhaps even use a light-weight
JVM.

Yet another approach would be to check out Fast-CGI (http://www.fastcgi.com/).

-- chris


 
Reply With Quote
 
 
 
 
Scott Yanoff
Guest
Posts: n/a
 
      09-03-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Let's say I have written a "Hello World" java program: h.java
> and I've compiled it to: h.class
> It emits a HTTP header line, a blank line, then the "Hello World!" line.
> Is there any way to directly run that as a CGI script, or do I have to
> use a shell script that calls java indirectly?


It works for /bin/sh and Perl because those interpret ASCII text whereas
Java wants a class file with bytecode in it. You're stuck calling java
via a shell script. Of course, the output will not go to the web
browser unless you output the proper content type, too. Is there any
reason why you can't write this as a servlet and use a servlet runner or
application server to execute it?


--
-Scott
(E-Mail Removed) | http://www.yanoff.org | AOL IM: SAY KJY

 
Reply With Quote
 
RobertMaas@YahooGroups.Com
Guest
Posts: n/a
 
      09-08-2003
{{Date: Tue, 2 Sep 2003 16:25:34 +0100
From: "Chris Uppal" <(E-Mail Removed)-THIS.org>
If the CGI program does a small enough amount of work for the JVM
startup time to be significant, then it'd be worthwhile trying to run
it in pure interpreted mode (if your particular JVM supports it) or
perhaps even use a light-weight JVM.}}

java -version
java version "1.2.2"
Classic VM (build jdk1.2.2-FreeBSD:root:2000/11/25-02:08, green threads, nojit)

So that version doesn't have the pure interpreted mode, right?

{{Yet another approach would be to check out Fast-CGI
(http://www.fastcgi.com/).}}

That mentions mod_fastcgi, so how do I find out whether my ISP has it
installed/available or not? whereis doesn't even show mod_macro which
it definitely does seem to have:
Server: Apache/1.3.26 (Unix) mod_macro/1.1.1

 
Reply With Quote
 
RobertMaas@YahooGroups.Com
Guest
Posts: n/a
 
      09-08-2003
{{Date: 2 Sep 2003 07:37:55 -0700
From: (E-Mail Removed) (LDV)
To run your Java CGI directly, you have to use a binary
wrapper/launcher (painfully slow)}}

That sounds worse than just indirecting via a shell script.

{{or compile it to a native binary using GCJ (available now) or
Excelsior JET (Linux version is coming soon)}}

Do you happen to know how to determine whether either is already
installed/available on my ISP (FreeBSD)?

 
Reply With Quote
 
RobertMaas@YahooGroups.Com
Guest
Posts: n/a
 
      09-08-2003
{{Date: Wed, 03 Sep 2003 14:01:44 -0500
From: Scott Yanoff <(E-Mail Removed)>
It works for /bin/sh and Perl because those interpret ASCII text
whereas Java wants a class file with bytecode in it.}}

Too bad Java doesn't accept an ASCII text script that simply tells the
name of the class file to use. I was hoping for some trick like that.

{{You're stuck calling java via a shell script.}}

Yeah, that's what I did prior to asking if I can do it more directly:

1 -rw------- 1 rem user 219 Sep 1 03:44 h.java
class h
{
public static void main(String args[])
{
System.out.println("Content-type: text/html");
System.out.println("");
System.out.println("Hello World!");
}
}

1 -rwxr--r-- 1 rem user 42 Sep 1 03:53 h-java.cgi*
#! /bin/sh
/usr/local/jdk1.2.2/bin/java h

http://www.rawbw.com/~rem/cgi-bin/h-java.cgi

{{Of course, the output will not go to the web browser unless you
output the proper content type, too.}}

Yeah, I already did that, see definition of main in h.java above.

{{Is there any reason why you can't write this as a servlet and use a
servlet runner or application server to execute it?}}

Yes: I don't know whether my ISP supports java servlets, nor how to
find out, and if supported then how to set up the hello program that
way. Do you happen to know either?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Java program evoke and run a FORTRAN program directly? Shawn Java 2 12-06-2006 07:08 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
FireFox is not taking Care of any Validator and doest invoke any... Malik Asif Joyia ASP .Net 2 08-12-2005 10:11 AM
How to set and highlight text in JTable cell on selection and/or invoke cell editor directly. news.rcn.com Java 1 07-12-2004 10:22 PM
Preview image directly on PC, save directly to HD Patrick M. Digital Photography 3 01-07-2004 08:29 PM



Advertisments