• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to call servlet class and it's methods from shell script

 
rama ilango
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i can call java class from shell script .
but i can't call methods of java and sevlet.
please reply me.
[ December 16, 2008: Message edited by: rama ilango ]
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15495
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

You can run a Java program from a shell script the same way as you do on the command line, by adding a command like:

java packagename.ClassName

to the script (where ClassName is the name of a class that contains a main() method).

Why would you want to call a servlet from a shell script? Please explain in more detail what you want to achieve.
 
Tim Holloway
Saloon Keeper
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets are designed to be used inside the operating environment of a JEE web application container. The container provides considerable infrastructure, plus it routes traffic to and from the servlet.

There are 2 reasons I can think of for wanting to run servlet code from a command line:

1. You have some sort of function you wish to use but you want to be able to invoke it via a batch process instead of by way of a web request.

2. You want to test the code in the servlet as part of an offline test suite.

For reason 1, you have a couple of options. If you want the actual servlet to function, use a command-line based utility such as wget to send a request to the server and retrieve the request results. If you want the logic but don't want to have a web server running, the same general rules as reason 2 apply.

For reason 2, where you don't want to talk to a running server, you can set up a batch server simulation such as the Cactus test tool. Cactus can imitate much of the infrastructure that an application server provides, but it's quicker to launch, since it's not a full-blown web server.

If you just want logic functionality, the best thing to do is to move the business logic itself outside of the servlet class and into a POJO business-object class. Then you can have the servlet invoke its functionality for online use, or invoke it directly for offline use.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic