Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jar Archive and Servlets  RSS feed

 
Nick Lebian
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Is it possible to run my Servlet, whose classes are in a jar archive (including the class with the doPost method)? If yes, how have I to configure the web.xml file (I'm using tomcat)?
Thanks,
Nick
 
Panagiotis Varlagas
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you:
(1) Create a WAR file for your project (in whatever way your IDE provides for that purpose) and
(2) Deploy that WAR file to Tomcat in whatever way is appropriate for that servlet engine?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nick,
Regardless of how you deploy your web app (war file or not), if the jar file containing the servlet is placed within the WEB-INF/lib folder of your web app, it will be in the classpath of the app.
In your web.xml you would create servlet and servlet mapping declarations as approriate. Or is it the format of these declarations that has you stumped? If that's the case, here's a simple example lifted from one of my web.xml files:

This is just one way to deal with a servlet. Your needs may vary. Point is, the entries in the web.xml are orthogonal to whether your servlet is in a jar or not, as long as it is in the classpath.
hth,
bear
[ June 20, 2003: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. One of the bartenders is soon going to ask you to change your name, as "Nick Someone" does not conform to Ranch policies. Why not do them a favor and beat them to the punch?
 
Nick Lebian
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response. But I think i still don't understand it. I have a jar File named "mypackage.jar". I deploy it in the web-inf/lib folder. What have I to change now in the web.xml file, if the class which shall be mapped to a URI is in this jar-File?
Nick
Whats wrong with my nick? ;-)
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No changes. It will "just work"

And yah, the official "change your name" request. Please.
 
Nick Lebian
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't work. There only comes this error message:
java.lang.IllegalArgumentException: Not an HTTP URL:java.io.IOException: HTTP response code: 500
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like your URL is malformed.
Further responses will be available when your name is changed to conform to Ranch standards. Not to be a bully, but you have now been officially asked.
bear
[ June 21, 2003: Message edited by: Bear Bibeault ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!