Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

set up jar file as web service

Posted on 2004-09-28
5
Medium Priority
?
180 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
[X]
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
  • 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 750 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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:
Suggested Courses

609 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