This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes problem while executing the JAR written using ANT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "problem while executing the JAR written using ANT" Watch "problem while executing the JAR written using ANT" New topic
Author

problem while executing the JAR written using ANT

meenakshi shankar
Greenhorn

Joined: Sep 17, 2011
Posts: 11
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.



Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

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?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
meenakshi shankar
Greenhorn

Joined: Sep 17, 2011
Posts: 11
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

Joined: Sep 17, 2011
Posts: 11
hi everyone, i still haven't been able to figure out a solution.. can someone please help??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
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.


Ping & DNS - my free Android networking tools app
meenakshi shankar
Greenhorn

Joined: Sep 17, 2011
Posts: 11
what exactly should i give as a value for main-class??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
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

Joined: Sep 17, 2011
Posts: 11
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
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
So the problem is solved now? If not, inspect the jar file as I said earlier.
meenakshi shankar
Greenhorn

Joined: Sep 17, 2011
Posts: 11
its not solved yet. will check the jars as you said and let you know.
meenakshi shankar
Greenhorn

Joined: Sep 17, 2011
Posts: 11


this is the structure of the jar.

and i still get the same error



meenakshi shankar
Greenhorn

Joined: Sep 17, 2011
Posts: 11
could it be because it doesn't recognize the Welcome.jsp to which am redirecting inside my WelcomeServlet code?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
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

Joined: Sep 17, 2011
Posts: 11
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
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
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

Joined: Sep 17, 2011
Posts: 11
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..
 
wood burning stoves
 
subject: problem while executing the JAR written using ANT