Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

set up jar file as web service

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
type mismatch (Object[] to double[] 4 33
runtime exception 2 41
going to wrong jsp page 2 33
SequenceInputStream example 3 19
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

840 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