Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

problem while executing the JAR written using ANT

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have written a simple hello world app using Spring and an ANT script to generate JAR file for the hello world app. The JAR is getting generated and the classes are getting compiled properly. I then copied the JAR into my tomcat webapps folder, started tomcat and loaded the index.jsp page. When i tried to navigate from the index.jsp page my Servlet inside the JAR is not getting recogonized. it throws the below given exception.



can someone please tell me why my Servlet class is not getting recogonized?

my directory structure is




my build.xml is



i tried creating JAR using eclipse. This also gives errors.




can someone help, please?

this is the structure of the jar that is being generated.



 
Sheriff
Posts: 22645
123
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

If you read the error message, it says "Wrapper cannot find servlet class my.hello.servlet.WelcomeServlet or a class it depends on". Are all dependencies available as well?
 
meenakshi shankar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The index.jsp page has a button. When i click on the button, the control is transferred to the WelcomeServlet. I have attached the code of WelcomeServlet below for your reference.

 
meenakshi shankar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everyone, i still haven't been able to figure out a solution.. can someone please help??
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Getting errors during build time is no good. But you can easily check what's in the jar file being generated: run "jar -tf helloworld.jar" on the command line. If the servlet is not in there, or not with the correct class name, you know where to start looking.

A quick glance at the build file shows that the value of the "main-class" property is apparently incorrect.
 
meenakshi shankar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what exactly should i give as a value for main-class??
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't analyzed how it's used - presumably you would know that. I just noticed that its value is "/my/hello/WelcomeServlet.class" whereas later on you mention a class named "my.hello.servlet.WelcomeServlet" - are those supposed to refer to the same class?
 
meenakshi shankar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes.. the same class.. i was just trying out different combinations of giving values to "main-class", because am new to ant scripting..
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the problem is solved now? If not, inspect the jar file as I said earlier.
 
meenakshi shankar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its not solved yet. will check the jars as you said and let you know.
 
meenakshi shankar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


this is the structure of the jar.

and i still get the same error



 
meenakshi shankar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could it be because it doesn't recognize the Welcome.jsp to which am redirecting inside my WelcomeServlet code?
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you trying to accomplish by "running the jar"? The class WelcomeServlet does not have a "main" method, so it couldn't possibly work.

You didn't say what your "main-class" looks like now, but it must not include the ".class" extension - as its name implies, the property takes a class name, not a file name.

You should read up on jar files: http://download.oracle.com/javase/tutorial/deployment/jar/index.html

could it be because it doesn't recognize the Welcome.jsp to which am redirecting inside my WelcomeServlet code?


The problem can't be related to what that class does, because the class isn't even found, much less is any code in it being executed.
 
meenakshi shankar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are right. i should not be running the jar. And because my WelcomeServlet does not have a main method, is it necessary to include "main-class"?? and ok, will read up about jars first.

thanks a lot
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

And because my WelcomeServlet does not have a main method, is it necessary to include "main-class"?


No. Asking this question indicates that you do not understand what "main-class" does, nor how jar files are used in web apps, and how they differ from jar files used for desktop apps.
 
meenakshi shankar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i do not understand what exactly "main-class" does. and also the diff between how jar files are used in web apps and desktop apps. would be glad if you can explain..
 
The only cure for that is hours of television radiation. And this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic