Solved

set up jar file as web service

Posted on 2004-09-28
5
171 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

696 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