Solved

set up jar file as web service

Posted on 2004-09-28
5
167 Views
Last Modified: 2013-11-24
Hello all,

I have created a jar program that takes two required parameters and two optional parameters.  From the DOS command line editor, it works great.  However, the whole reason of creating the program was to turn it into a web service.  This program will not be run from a browser but I need it to accept the parameters from user input (in a browser) and then run on the web server itself.  Any clues as to where I can start?

My web server is IIS 5.0 running on a WinXP machine.

Any help is appreciated.

Thanks.
0
Comment
Question by:dds110
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:gdrnec
ID: 12173721
Not sure exectly what you mean by not be run from a browser. I guess you mean not client side (applet style).

Eaiest way to start is to download tomcat from www.apache.org and install it as a connector with IIS and deploy your jar there. Of course, to run as a web service, you will need to wrap your code in a servlet so that Tomcat can execute it.

As far as creating servlets go, I would look at http://www.java.sun.com and check out the tutorials. Pretty simple though.

If you need more help, come back.

Geoff
0
 
LVL 8

Author Comment

by:dds110
ID: 12173923
OK, maybe web service was the wrong phrase to use.  Basically, I need a CGI program.  A program that will take parameters passed to it via server variables and then run.
0
 
LVL 4

Accepted Solution

by:
gdrnec earned 250 total points
ID: 12174022
Right, I figured that was what you were getting at.

If your code is already in java, you might as well proceed down that path.

Installing Tomcat is relatively easy and getting IIS to talk to it is pretty simple as well, just connect over 8080.

To change what you have in your jar (probably a class with a main method) to something that Tomcat likes is quite simple. Just create a servlet (extend javax.servlet.http.HttpServlet and call your class's methods from the doPost/doGet methods. Any response you want to send back to the browser just gets written to the javax.servlet.ServletResponse.getWriter().

When you re package your jar will need to package like a web app and have a web-inf directory that holds a web.xml file that looks like the following and a classes directory that holds your servlet and other classes pointed to by the web.xml file.

Other than that, nothing to it. More information at www.java.sun.com

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

    <servlet>
        <servlet-name>LogViewerServlet</servlet-name>
        <servlet-class>com.loadsaenergy.awthandheld.server.LogViewerServlet</servlet-class>
    </servlet>    
                         
    <servlet-mapping>
        <servlet-name>LogViewerServlet</servlet-name>
        <url-pattern>/viewlogs</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
      <welcome-file>
            index.html
        </welcome-file>
    </welcome-file-list>

</web-app>



Hope this helps.

Geoff
0
 
LVL 8

Author Comment

by:dds110
ID: 12174092
This all seems a bit extreme just to be able to pass a few parameters to a jar file.  I've used Tomcat before and I agree that it is simple.  However, I don't think this is the road I want to travel down.  I've seen some articles that mention passing the server variables to a script file (windows batch or linux script) and then having the script file call on the jar.

I can assure you gdrnec that at this point, you are more than well-deserving of the points.  You've put a good bit of effort into your comments and I'm sure they work.  I was just looking for something a bit simpler.
0
 
LVL 92

Expert Comment

by:objects
ID: 12174969
> I've seen some articles that mention passing the server variables to a script file (windows batch or linux
> script) and then having the script file call on the jar.

you're still going to need something that accepts the requests, extracts the parameters, and calls the script.
If you don't want to use a servlet then you're probably asking the q in the wrong TA. The CGI TA may be more appropriate.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ArrayIndexOutOfBoundException 9 82
Error trying to install RTMT Win7 5 60
reverse digits of a number using for loop 5 42
How to convert from xls to xlsx using java 7 39
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question