Hi, A WAR file is just a JAR file with special locations inside it. The Tomcat classloaders all extend java.net.URLClassLoader which can read from JARs.
So if you could open a WAR file and create a new URLClassLoader with the URL to the WAR file's WEB-INF/classes directory, for example, you'd be there. The java.util.jar package has methods that get all almost all the way there, but I think you might have to expand the WAR. Yoav Shapira Millennium Research Informatics >-----Original Message----- >From: Steve McWilliams [mailto:[EMAIL PROTECTED] >Sent: Thursday, August 26, 2004 2:19 PM >To: [EMAIL PROTECTED] >Subject: Loading classes from a WAR file outside of Tomcat > >Hello, > >I am wondering if anyone can suggest an easy way to reuse WAR files >outside of Tomcat. We use Tomcat 5.0.27 and deliver out application >bundled up in a WAR file, which we do not explode at runtime. > >Ideally I would like to be able to reuse some of the classes in our WAR >file from a stand alone java application outside of Tomcat (that does some >administrative tasks and gets called by InstallShield at installation >time). I would rather not have to explode the WAR file to do this. > >I would like to be able to do something like this in my stand alone java >code, in order to find the class in the WAR file: > >WARClassLoader loader = new WARClassLoader(); >loader.addWAR(warFileAbsolutePath); >Class clazz = Class.forName(desiredClass, true, loader); > >I could write my own WARClassLoader, but it seems like such a thing must >already exist. I poked around through the Tomcat source but everything >seems to be snarled up in the Container and DirContext overhead somehow. >I also looked at the Tomcat WebappLoader, StandardClassLoader, and >WebappClassLoader but none of those look like they can read into a WAR >file. > >Thanks in advance. > >Steve McWilliams >Software Engineer >Emprisa Networks >703-691-0433x21 >[EMAIL PROTECTED] > >The information contained in this communication is intended only for the >use of the recipient named above, and may be legally privileged, >confidential and exempt from disclosure under applicable law. If the >reader of this communication is not the intended recipient, you are hereby >notified that any dissemination, distribution or copying of this >communication, or any of its contents, is strictly prohibited. If you have >received this communication in error, please resend this communication to >the sender and delete the original communication and any copy of it from >your computer system. Thank you. > > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
