wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes Compiling a dynamic web app from command line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Compiling a dynamic web app from command line" Watch "Compiling a dynamic web app from command line" New topic
Author

Compiling a dynamic web app from command line

Andreas Markitanis
Greenhorn

Joined: Apr 15, 2010
Posts: 21
When using eclipse, compiling the web app and running it on a server is relatively straight-forward. Eclipse knows where the apache tomcat libraries are ( such as servlet-api.jar etc)

If you're writing an ant script to compile the classes from the command line... I get an error which I understand where it comes from...basically...javac complains because it cannot find the javax.* libraries.

adding the servlet-api.jar under WEB-INF/lib resolved the problem but now Tomcat complains with the following:

INFO: validateJarFile(/Library/Tomcat/apache-tomcat-6.0.20/wtpwebapps/iSquirrel/WEB-INF/lib/servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

anyone knows how to fix this?
Generally, what needs to be included in WEB-INF/lib so that the web app compiles correctly using command-line? I would suspect that the tomcat jar files are not needed as long as you include them in the classpath when compiling?

Thanks a lot
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Correct, and in fact including them in WEB-INF/lib creates an error. As you saw.
Andreas Markitanis
Greenhorn

Joined: Apr 15, 2010
Posts: 21
So to fix the error...do I simply add the tomcat lib classpath when compiling via the ant script?

thanks
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Yes


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16014
    
  20

Martijn Verburg wrote:Yes


No.

You can't add a library directory to a classpath in Java and use what's in the jars in that directory. That's not how the JVM works. It won't automatically search the jars.

However, in most cases, for a J2EE build, if you include $TOMCAT_HOME/lib/jsp-api.jar and $TOMCAT_HOME/lib/servlet-api.jar to your compile classpath that's all you need. You don't need every jar in $TOMCAT_HOME/lib.


Customer surveys are for companies who didn't pay proper attention to begin with.
Andreas Markitanis
Greenhorn

Joined: Apr 15, 2010
Posts: 21
I agree with Martin as my problem was fixed.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

To be clear here I agree with Tim, my flippant yes response was simply because I mis-interpreted by what you meant as TOMCAT CLASSPATH. Tim is in fact correct in that you should have specific JARs in your CLASSPATH as opposed to an entire folder.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Compiling a dynamic web app from command line