Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat 7 embedded and web app jar files

 
Renz Alexander
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi can any one tell me how to add the class path of my web application. i've tried



a modified version of this one, but it any references the one in the base path.

i also tried the bootstrap class

but still it doesn't load the web apps classes,
and the server.xml used is the same xml that come with tomcat
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you deploy a webapp in tomcat, the WEB-INF/classes directory is automatically added to that webapp's classpath, as are all the jars in its WEB-INF/lib directory. There's no explicit action that needs to be taken.

That's actually true for any J2EE-compliant appserver, not just Tomcat. It's part of the spec.
 
Renz Alexander
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes but i'm using spring in my web app which seems to be the problem. i don't know how to add the TomcatInstrumentableClassLoader to an embedded tomcat.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good one!

Normally, I'd say add it to the classpath of the code that instantiates Tomcat, but Tomcat is setting up its own classpath.

The various jars that are in the global application classpath - meaning things like the basic support jars, jdbc drivers and the spring weaver jars - are located in $CATALINA_HOME/lib and Tomcat scans that directory and adds each jar into its global classpath.

As it happens, the embeddable Tomcat bean has a "catalinaHome" property. I think if you set that appropriately it will work.
 
Renz Alexander
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i've tried reading the api but i still can't find the catalina home bean and before aything i would like to remind everyone that i'm using tomcat 7's new embeddable tomcat feature for future reference specifically org.apache.catalina.startup.Tomcat; and not org.apache.catalina.startup.Embedded;. and sory if i seem rude it's just that it's eating at me for a few days now and i'm stuck.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no need to apologize for pointing out what you'd already said to those of use who are too blind to realize what you said.

You're living on the bleeding edge here. It appears that this way of starting Tomcat is still under development. I would expect it to be augmented by other classes before it's truly first-class and some API methods may even change. So in the short term, I'd seriously consider using the old-style embedded Tomcat bean. Yes, I know it's deprecated, but deprecated doesn't mean non-functional in Java (that's why there's deprecation instead of just dumping you off the cliff, a la Microsoft). Sometimes stuff gets de-deprecated when the replacement turns out to be less than ideal.

However, if you read the horribly-formatted sketchy JavaDocs, there's a sentence that indicates the key to you problem, I think:


Which implies that you'd put your jar in your main application classpath.

Which isn't exactly comforting, since you end up dumping Tomcat support classes in the non-Tomcat classpath of your app, but the JavaDocs do say that this particular class is intended for use when you want to run embedded Tomcat quick-and-dirty.

The baseDir property is the string that holds the directory pathname to the embedded Tomcat base directory. It's also implied that if you set system properties "catalina.home" and/or "catalina.base" that they're operate in the usual way. Both of these properties would also be directory pathname strings. Athough I'd expect a really polished embedded tomcat class to support the option of supplying a properties object to the Tomcat object rather just pulling from system properties, which is much less flexible.

Obviously this particular facility still needs a lot of work.
 
Renz Alexander
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the help Tim. I just went with placing the spring and hibernate jars in my server. Its really annoying that i have to add the jars in my server but it's alright i was planning on adding some other functionality that needs spring and hibernate like a way to backup and recover my database.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic